Jump to content


Error: mysql_num_rows

  • Please log in to reply
1 reply to this topic

#1 phulla

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 01 March 2006 - 01:11 PM

My local machine i have
php v4.3.10
mysql v4.1.10-nt
apache v2.0.50

My uk2.net host has
php v4.3.11
mysql v4.0.24
apache v1.3.33

The following code works fine locally
    if ($conn) {
        $result = $dbConn->queryDB( "SELECT * FROM ajmerphull_mainnav WHERE display = 1 ORDER BY id ASC" );
<div id="nav" class="fudge">
    if (mysql_num_rows($result) >= 1) {
        $count = 1;
        while ($row = mysql_fetch_array($result)) {
            $last = ($count == mysql_num_rows($result) ? ' class="noborder"' : '');
            print (
            "<li". $last ."><b>[</b><a href=\"". $row['link'] ."\" accesskey=\"". $count ."\" title=\"". $row['title'] ."\">". $row['name'] ."</a><b>]</b></li>

Database class
    function queryDB($sql) {
        return mysql_query($sql) or die(mysql_error());


I can connect to the database i have replicated on the host using phpMyAdmin and execute the SQL statement and it returns the desired result.

On the host, outputing the value of $result returns a value of 1, which is correct.

I can not understand what's wrong with mysql_num_rows. If i remove the if statement, i get the same error for mysql_fetch_array.

I can not print_r(mysql_fetch_array($result)) to check the value.

Can anybody help?

You can see this live at [a href=\"http://ajmerphull.com\" target=\"_blank\"]http://ajmerphull.com[/a]


#2 XenoPhage

  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 01 March 2006 - 01:20 PM


Well, at first glance, it looks like you check to see if $conn is valid, but then you're calling it $dbConn when you do your query.. Are these 2 independent objects?

Are you sure that $conn is valid each time? If $conn fails, then $result is never populated with a valid resource. So when you try to get the number of rows, it will fail.

Try tossing some debug info in there. Inside the first if loop, do something like this :

    if ($conn) {
        print "Connection is Valid";
        $result = $dbConn->queryDB( "SELECT * FROM ajmerphull_mainnav WHERE display = 1 ORDER BY id ASC" );
    } else {
        print "Invalid Connection!";

Your second if statement could look something like this :

        if (isset($result) && (mysql_num_rows($result) >= 1)) {

I would recommend re-working this a bit, though. If you can't get a connection to the database, don't bother continuing. Display an error message instead of displaying partial data...
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users