tags:

views:

15

answers:

2

Hi Gang...

Please don't beat me if this is elementary. I searched and found disjointed stuff relating to pseudo columns. Nothing spot on about what I need.

Anyway... I have a table with some rows. Each record has a unique ID, an ID that relates to another entity and finally a comment that relates to that last entity.

So, I want to COUNT these rows to basically find what entity has the most comments.

Instead of me explaining the query, I'll print it

SELECT entity_id, COUNT(*) AS amount FROM comments GROUP BY entity_id ORDER BY amount DESC

The query does just what I want, but I want to echo the values from that pseudo column, 'amount'

Can it be done, or should I use another method like mysql_num_rows?

Thank you!!!

+3  A: 

It's just the same as with the other column – you use the mysql_fetch_* family.

Note that moving to the Mysqli extension is encouraged. See here why.

Artefacto
Thanks for the tip, Artefacto. Will do my research on improved MYSQL. I am SO behind in everything.
rob - not a robber
I thought we could send private messages here. Anyhow, do you do this for a living? How long does it take to assimilate the new MYSQL methods in PHP5? Obrigado!
rob - not a robber
@rob that would depend on several factors, including previous experience with databases, PHP, MySQL, etc. It is certainly easier to get familiar with a certain client database API than to learn SQL, for instance. And no, I've never programmed in PHP professionaly (only in Java).
Artefacto
+1  A: 

Once you have the row in, say, $row, you can simply use the value of $row['amount'].

Ignacio Vazquez-Abrams
Depending on how he fetched the row, it may not work.
Artefacto
Ignacio... you got it. As you can see, I am really new at this. Thank you very much.
rob - not a robber
I may not work, or it may need to be changed slightly?
Ignacio Vazquez-Abrams
If it needs to be changed slightly, by the definition of "needs", it does not work :p My point was that if he did `$row = mysql_fetch_row(...)`, then he'd have to use `$row[1]`.
Artefacto