Jump to content

mysql_num_rows


zintani

Recommended Posts

Hello,

While I was working on my code I faced this problem

(Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\showlist.php on line 31

Call Stack

# Time Memory Function Location

1 0.0269 371408 {main}( ) ..\showlist.php:0

2 0.0611 383760 mysql_num_rows ( ) ..\showlist.php:31

)

And I tried to figure out why is this message appearing every time I invoke the code. Anyone can help please?

and here is my code

 echo "<br />";
$sql = "SELECT * FROM message, recipientinfo WHERE message.message_id = recipientinfo.mid AND (message.sender = 'kevin.hyatt@enron.com' AND recipientinfo.rvalue = 'michelle.lokay@enron.com' AND recipientinfo.rtype = TO )";
$done = mysql_query ($sql);
$show = mysql_num_rows($done); 
echo $show;

Another question please my database is larger than 500 MB which sometimes I find difficulties when I search using join feature between tables. Is there a method to increase the capability of phpmyadmin?

Thanks a lot

Link to comment
Share on other sites

Right, your query is failing. Change your mysql_query() line to this

 $done = mysql_query ($sql) or die("Query:<br>{$query}<br>Error:<br>".mysql_error());

 

However, I see why your query is failing. Here it is in a more readable format:

 $sql = "SELECT *
         FROM message, recipientinfo
         WHERE message.message_id = recipientinfo.mid
           AND (    message.sender = 'kevin.hyatt@enron.com'
                AND recipientinfo.rvalue = 'michelle.lokay@enron.com'
                AND recipientinfo.rtype = TO )";

 

It is failing because of the "TO" in the last condition. If you are trying to compare against a string then the value need to be in single quotes: 'TO'. If TO is a variable or constant then you will need to define it appropriately - if it is a string then it still needs to be in quotes. Personally I prefer to use explicit joins. I don't know if it is more efficient, but it is easier to see the relationships.

 

This is how I would have prepared that query

 $sql = "SELECT *

         FROM message
         JOIN recipientinfo
           ON message.message_id = recipientinfo.mid

         WHERE message.sender = 'kevin.hyatt@enron.com'
           AND recipientinfo.rvalue = 'michelle.lokay@enron.com'
           AND recipientinfo.rtype = 'TO'";

 

Don't be afraid to add line breaks and spacing to your code. It makes the code much, much more readable and logical for a human.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.