Jump to content

Echo out the number of records in a mysql table with PHP?


Far Cry

Recommended Posts

//Either
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
echo mysql_num_rows($result) . ' rows found!';
//or
$sql = "SELECT COUNT(*) AS count FROM table";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo $row['count'] . ' rows found!';

 

I would use the first one, if I'm pulling queries to use, and the second one for counts only.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.