Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row count

Status
Not open for further replies.

Impothster

Technical User
Apr 17, 2003
14
GB
I am fairly new to this but have been making some good progress thanks to these forums. All I would like to do is count the number of rows in a particular table and echo the number to the browser. I have had a crack at it with no success. Connection to the db is ok and retrieving data from the table is ok, but I can't get a count value output. Any help gratefully received.
NB. Using latest PHP and MySQL.
 
there are two ways:
$sql="select count(*) from table";
$rs=mysql_query($sql);
$row=mysql_fetch_row($rs);
echo "Count-"$row[0];

second way:
$sql="select * from table";
$rs=mysql_query($sql);
echo "Count-"mysql_num_rows($rs);

note: first method is faster.


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top