function get_total_urls(){
$total = mysql_query("SELECT COUNT('url_key' FROM 'urls')");
$url_total = mysql_result($total, 0);
echo $url_total;
}
returns error:
Warning: mysql_num_rows() expects parameter 1 to be resource
I have been browsing to find the cause, most people get it due to the lack of mysql_query but I'm using that.
Any ideas where I'm going wrong? I know the database information is correct.
Thanks.
Your query is failing. Therefore, $total
is receiving false
instead of the MySQL resource. Hence the error.
This is because you are using single quotes instead of back ticks (or nothing) and an incorrect syntax for COUNT()
.
SELECT COUNT(`url_key`) FROM `urls`;
Note: When in doubt, run your query directly against MySQL (from CLI or PHPMyAdmin) or use mysql_error()
.
Your SQL query is invalid, the correct line in PHP should be:
$result = mysql_query("SELECT COUNT(url_key) FROM urls");
Try this
function get_total_urls(){
$total = mysql_query("SELECT COUNT(`url_key`) FROM `urls` ") ;
$url_total = mysql_num_rows($total);
echo $url_total;
}