check if mysql query returns empty set

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by wjh2303, Jun 10, 2009.

  1. wjh2303

    wjh2303 New Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    0
    how can i check if a mysql query in php has returned an empty set.
    I have a page that requires two queries, but want to format it slightly differently if the first query returns the empty set, i.e:

    if(1stquery=emptyset){
    format this way
    }
    else{
    format that way
    }

    hope thats clear enough

    TIA
     
  2. garrettroyce

    garrettroyce Generally Helpful Member Community Support

    Messages:
    4,079
    Likes Received:
    131
    Trophy Points:
    63
    Code:
    $result = mysql_query('blah blah blah this is your query');
    if ($result) {
         if (mysql_num_rows($result) == 0) {
            // do one thing
         }
         else {
            // do another thing
         }
    }
     
  3. wjh2303

    wjh2303 New Member

    Messages:
    139
    Likes Received:
    0
    Trophy Points:
    0
    yup, thats done it, thanks
     

Share This Page