"T. Relyea" <no****@nospam.com> wrote in message news:<De*******************@twister.nyroc.rr.com>. ..
Matt Schroeder wrote:
Does anyone know how to count how many rows are in a mysql table? This is
what I have, but it doesn't work right:
<?
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("database",$db);
$sql = "SELECT COUNT(*) FROM table";
$result = mysql_query($sql);
echo "$result";
?>
This returns "Resource id #3". All it should say is '2'. Can anyone tell me
what I'm doing wrong?
Thanks,
Matt
You want to use:
mysql_num_rows($result);
Use mysql_num_rows($result) when your query is "SELECT * FROM table";
If your query is "SELECT COUNT(*)...", use
$sql = "SELECT COUNT(*) FROM table";
$result = mysql_query($sql);
$num = mysql_result($result, 0);
echo $num;
---
"If there is a God, he must be a sadist!"
Email: rrjanbiah-at-Y!com