Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    mysql_num_rows not working

    Anyone have a clue why this doesn't work? and why it processes the following error?

    Code:
    $checkquery = mysql_query("SELECT * FROM titles WHERE id>'0' ");
    
    $num_rows = mysql_num_rows($checkquery); //Line 113
    if ($num_rows = 0)
    {
      echo '<b>No Titles Found.</b><br><br><br>';
    }
    The error below
    Code:
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/y/a/n/yankeefaninkc/html/argyle2/admin.php on line 113

  • #2
    Regular Coder che_anj's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    157
    Thanks
    12
    Thanked 3 Times in 3 Posts
    PHP Code:
    $num_rows=mysql_num_rows($checkquery);
    if(
    mysql_num_rows($num_rows) < ){
              echo 
    '<b>No Titles Found.</b><br><br><br>';

    Last edited by che_anj; 12-04-2008 at 02:52 PM.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    As always we say, add proper error checks to your query.
    Code:
    $checkquery = mysql_query("SELECT * FROM titles WHERE id>'0' ");
    should be
    PHP Code:
    $checkquery mysql_query("SELECT * FROM titles WHERE id>'0' ") or die(mysql_error()); 
    PS:When comparing against a numeric type filed, avoid using quotes around values.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Hi,

    I am still getting the same mysql_num_rows error. Here is what I put in

    Code:
    function etitles() {
    
    $checkquery = mysql_query("SELECT * FROM titles WHERE titleid>'0' ") or die(mysql_error());;
    
    
    echo '<hr><center><h2>Administrator Control Panel</h2></center><hr><br><br>';
    echo 'Select the user you wish to edit.<br><br>';
    $num_rows=mysql_num_rows($checkquery);
    if(mysql_num_rows($num_rows) < 1 ){
              echo '<b>No Titles Found.</b><br><br><br>';
    }

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Code:
    $num_rows=mysql_num_rows($checkquery);
    if(mysql_num_rows($num_rows) < 1 ){
              echo '<b>No Titles Found.</b><br><br><br>';
    }
    What's that?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Dunno thats the code che_anj posted.

    All I want it to do is check if there are any records in a table, and if not, post there isn't any.

  • #7
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by masterofollies View Post
    Hi,

    I am still getting the same mysql_num_rows error. Here is what I put in

    Code:
    function etitles() {
    
    $checkquery = mysql_query("SELECT * FROM titles WHERE titleid>'0' ") or die(mysql_error());;
    
    
    echo '<hr><center><h2>Administrator Control Panel</h2></center><hr><br><br>';
    echo 'Select the user you wish to edit.<br><br>';
    $num_rows=mysql_num_rows($checkquery);
    if(mysql_num_rows($num_rows) < 1 ){
              echo '<b>No Titles Found.</b><br><br><br>';
    }
    If you'll notice, you are actually performing the mysql_num_rows() function twice, which is where your error is coming from. You first use it and place the return value in the variable $num_rows. Then, in the if statement, you run mysql_num_rows() again (on the variable you just set). Here's how it should be:

    PHP Code:
    $num_rows mysql_num_rows($checkquery); //$num_rows now contains the number of rows from the query
    if ($num_rows ) {
              echo 
    '<b>No Titles Found.</b><br><br><br>';


  • Users who have thanked JohnDubya for this post:

    masterofollies (12-04-2008)

  • #8
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Ah I see, this is the first time I've used mysql_num_rows so it's a learning experience. Thanks

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Always check the manual, before using any new function. You'd get plenty of examples and related stuffs from there.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    masterofollies (12-05-2008)

  • #10
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I actually read that before posting, but I couldn't find an example like mine. Well I am sure there was but I didn't understand it. Maybe I should play with a few of the examples and learn.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •