www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] mysql_num_rows() small problem

  1. #1
    Join Date
    May 2012
    Posts
    7

    resolved [RESOLVED] mysql_num_rows() small problem

    Hi guys i have this pretty straight peice of code, that checks if it brought back any rows so i can change what dropdown options become available.

    PHP Code:

    $queryvoid 
    $this->db->query("SELECT * FROM 'test' WHERE test_id = '1' GROUP BY width ORDER BY width");
    $num_rows mysql_num_rows($queryvoid);

    if (
    $num_rows ){ echo "Results exist<br>"; } 
    but this returns an error

    PHP Code:
    mysql_num_rows(): supplied argument is not a valid MySQL result resource 
    is there something im missing with this?

    Regards
    David
    Last edited by david.mitchell; 05-09-2012 at 05:40 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    It means that the MySQL server choked on your query for one reason or another, so mysql_query() returned Boolean false instead of a query result resource.

    In other words, check the result for false, and if so, do whatever sort of debugging you prefer at that point.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2011
    Location
    Lancashire
    Posts
    35
    Hi,
    I'm no expert but for the code you have supplied, it looks like you are not running your query. Before you count your rows you will need to run the query :
    $r=mysql_query($queryvoid);

    mysql_num_rows function takes only one argument: the query result variable (i.e. $r in this case), therefore you code should read:

    $num_rows=mysql_num_rows($r);

    try that and see if it works
    regards
    LF

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    Quote Originally Posted by LutinFou View Post
    Hi,
    I'm no expert but for the code you have supplied, it looks like you are not running your query. Before you count your rows you will need to run the query :
    $r=mysql_query($queryvoid);

    mysql_num_rows function takes only one argument: the query result variable (i.e. $r in this case), therefore you code should read:

    $num_rows=mysql_num_rows($r);

    try that and see if it works
    regards
    LF
    Good point, in that on a second look, I see the original code executes the query via an unknown (to me at this point) object method $this->db->query. It may be that this is not even a mysql_query() call, in which case mysql_num_rows() is of no use at this point. Instead you would need to use whatever the comparable method is for that db object you are using.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    May 2012
    Posts
    7
    it ended up being


    PHP Code:
    $queryvoid $this->db->query("SELECT * FROM 'test' WHERE test_id = '1'"); 
    $num_rows $this->test->num_rows

    if (
    $num_rows ){ echo "Results exist<br>"; } 
    Thanks guys

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles