Results 1 to 3 of 3

Thread: Checking if query has records

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Checking if query has records

    Hi all, i have a query that i want to check to see if there are any records. What i have been given doesnt seem to be correct.

    This is is a loop, i simply want to check if there is a record.

    PHP Code:
    $imgQuery mysql_query("SELECT * FROM meltdown_images Where download_id='" $myrow[1] . "'",$db);

    while (
    $rowQuery mysql_fetch_array($imgQuery));
            
    // Records    
            
    } else {
            

    // No records    
        


  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Checking if query has records

    You can use mysql_num_rows() to check the number of records return from your query.

    If you want to return only one record use "LIMIT 1" in your query so you don't return records you don't need.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Checking if query has records

    If all you want to do is check for records then alter your query

    PHP Code:
    $records mysql_query('select count(*) from meltdown_images where `download_id` = '.(int)$myrow[1]);

    $recordCount mysql_result($records)[0]; 

Posting Permissions

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



Click Here to Expand Forum to Full Width