I am a newbie in PHP and mySQL. I got stuck with a mySQL function and could not figure out the problem. I would appreciate very much if any expert in this forum could help.
I learned and reused a function get_category_name($catid) from page 554, listing 25.7 of the book PHP and mySQL - web development. The code is as following:
function get_category_name($catid)
{
$conn = db_connect();
$query = " select catname
from categories
where catid = $catid";
$result = @($query);
if (!$result)
return false;
$num_cats = @mysql_num_rows($result);
if ($num_cats ==0)
return false;
$result = mysql_result($result, 0, "catname";
return $result;
}
I dont know why mysql_num_rows($result) could not get any value while mysql_query($query) had returned some values in the $result. I got stuck where $num_cats = @mysql_num_rows($result) return false.
Thanks again for help.