@mysql_num_rows($result) problem

Codes here !

Moderators: macek, egami, gesf

royalbi
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Mar 08, 2003 6:01 am

@mysql_num_rows($result) problem

Postby royalbi » Sat Mar 08, 2003 7:01 am

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 = @mysql_query($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 any great help.
Royalbi

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Sat Mar 08, 2003 10:53 am

take off the @ to see what error you are getting. the @ does makes it so it does not output error. which you should't use if you are testing.

If you are getting some results it should work.

royalbi
New php-forum User
New php-forum User
Posts: 2
Joined: Sat Mar 08, 2003 6:01 am

Postby royalbi » Sat Mar 08, 2003 5:03 pm

Thanks for your response.

I did try to leave the @ sign out the code. I still had the same problem.

Now i'm getting confused whether i had some results from the query. If i did not have any results, it should return false. I test with echo right after the query, i was quite sure that it had returned result but somehow mysql_num_rows always return 0.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest