PDA

View Full Version : PHP/MySQL display number of records


VENCO
02-26-2005, 12:53 PM
I am trying to alter a script I have to include another feature.

Currently I have $poweredby .= "There are XXX submitted items.";
which puts it in the format I need, but I need XXX replaced with the actual number. I suppose the best way to do that is to just count the number of records in one of the tables of my database which includes those items.

How do I do this?

Thank you

Silmaril8n
02-26-2005, 01:36 PM
mysql_num_rows();

That will show you the number of returned rows in the last executed query.

Viper007Bond
02-26-2005, 08:19 PM
MySQL's COUNT is also sometimes a good option, depending on what you're doing.

ColemanHamilton
02-27-2005, 12:20 AM
Stick with the mysql_num_rows(); its a very powerful little function. Which is very useful on what i do. I use it all the time.

Mr. Popularity
02-27-2005, 05:45 AM
this is true... some people who dont know better actually select * and load all that data into memory :rolleyes:

VENCO
02-27-2005, 01:21 PM
Problem is I'm not really sure what I'm doing. I've been starting to be able to edit some php, but constructing it from the beginning is a whole different story.

Viper007Bond
02-27-2005, 05:19 PM
Stick with the mysql_num_rows(); its a very powerful little function. Which is very useful on what i do. I use it all the time.
Yes, but to get num_rows to work, you gotta do a query. If you're only wanting the number of rows for something, why select up a column or something and have to transfer all of that data when COUNT will just spit back an integer?

Silmaril8n
02-27-2005, 07:00 PM
Yes, but to get num_rows to work, you gotta do a query. If you're only wanting the number of rows for something, why select up a column or something and have to transfer all of that data when COUNT will just spit back an integer?
That's a good and very important point. COUNT would be better used when displaying paginated data, where mysql_num_rows is helpful for throwing in some useful stats on the current recordset.

Viper007Bond
02-28-2005, 02:25 AM
Yeah. If you're grabbing data and just want to know how much you got, then num_rows is what you want. If you're ONLY looking to count something in a table, then COUNT is what you want.