Need help wording if statement

Discussion in 'PHP' started by egdcltd, Feb 5, 2007.

  1. #1
    Okay, I'm running the following sql query

    			$sql = " SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "
    				WHERE item_in_shop = 0
    				AND item_in_warehouse = 0
    				AND item_duration > 0
    				AND item_owner_id = $user_id 
    				AND item_type_use = 50 ";
    
    			{
    				message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
    			}
    			$ammo = $db->sql_fetchrow($result);
    PHP:
    What I want to do is add some code like

    if(no entries found for search)
    {
    post message
    }

    I know how to do the message, but I'm not sure how to write the if statement.

    Could someone help please?
     
    egdcltd, Feb 5, 2007 IP
  2. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $sql = "[your sql statement here]";
    $rst = mysql_query($sql);
    
    if(mysql_num_rows($rst) > 0) {
      // code if found
    }
    else {
      // code if not found
    }
    Code (markup):
     
    daboss, Feb 5, 2007 IP
  3. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the help
     
    egdcltd, Feb 5, 2007 IP