How can I return the amount of elements in a table that's in a mysql database?
Foxy
Help with mysql table (noob)
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Help with mysql table (noob)
You can do something like: "SELECT COUNT(*) AS total_records FROM mytable".
(#10850)
Re: Help with mysql table (noob)
I tried the sql query but I think I am doing something wrong, this is what I have:
$totalQ = "SELECT COUNT(*) AS total_records FROM ELEC";
$totalRecords = mysql_query($totalQ) or die(mysql_error());
But when I echo $totalRecords it prints "Resource id#3"
Please help,
foxy
$totalQ = "SELECT COUNT(*) AS total_records FROM ELEC";
$totalRecords = mysql_query($totalQ) or die(mysql_error());
But when I echo $totalRecords it prints "Resource id#3"
Please help,
foxy
Re: Help with mysql table (noob)
You should not only execute the query, but also fetch the result...
Code: Select all
$totalQ = "SELECT COUNT(*) AS total_records FROM ELEC";
$result = mysql_query($totalQ) or die(mysql_error());
$totalRecords = mysql_fetch_object($result);
echo $totalRecords->total_recordsRe: Help with mysql table (noob)
thanks that worked great