The other solution is to eliminate the subquery and count the number of number of rows per price in PHP. In either case your going to need to format the result set on the application side. So I would run a simple select for everything then handle the aggregate calculations on the application side while parsing the result set into a price => rows pair. You could also do as hash said and run the count query then a query for each individual row that pertains to the given price.

system
—
2010-02-01T05:50:29Z —
#10

SpacePhoenix, the less code you write, the less errors you have.Try to think of mysql_real_escape_string use in your code. And usefulness of other code too. I bet OP has his table with data already.

oddz, you don't need such a query. There can be huge amount of data. And we do not know, what type we well need. So, if you want scalable application, it must be done with different queries.

ma201dq, make a hyperlink.

SpacePhoenix
—
2010-02-01T06:41:27Z —
#11

@Shrapnel_N5

It was an example for the OP on how to do it, instead of mysql_real_escape_string on a live site they would use prepared statements. How do you suggest the OP does it?

system
—
2010-02-01T06:43:30Z —
#12

There is no use for mysql_real_escape_string, nor prepared statements in this code.Why not to learn PHP a bit?

SpacePhoenix
—
2010-02-01T07:04:28Z —
#13

ma201dq said:

Hi guys,

I need to group search results. while I can use "Group By (column_name)", my problem is when a search result is returned how to see what rows are within a group so i can do smomthing like:

we found 5 matches in group A, click here to see all

how you have you done this? can you pelase give me some ideas?

thanks

Shrapnel_N5 said:

There is no use for mysql_real_escape_string, nor prepared statements in this code.Why not to learn PHP a bit?

Shrapnel_N5, I suggest that you get some better glasses. If you had read ma201dq's original post (quoted above) you would have seen the it is to do with search results which might well mean the use of a form where the user selects something to search for that means user input and user input should never be trusted, hence the use of mysql_real_escape_string or preferably prepared statements.

You've a lot of proper words, but not a bit of understanding what does it mean There is no connection between your words and your code.Yes, there may be use of escaping. And even with no user input at all. But, of course, not in the way you wrote it. I wonder why don't you want to read mysql_real_escape_string page in documentation or at least run your code (with printing out mysql_error() added to it) to see actual result of it.