#1
  1. No Profile Picture
    msenefsky
    Guest
    Devshed Newbie (0 - 499 posts)
    How do I compare if/else with empty set from Db query? It doesn't recognize NULL or 0.

    if($search_text)
    {
    //query Db for Product Type
    $prod_type_query = "select DISTINCT product_type from PRODUCTS";
    $prod_type_result = mysql_query($prod_type_query);

    while($prod_type_row = mysql_fetch_array($prod_type_result))
    {
    $product_type = $prod_type_row['product_type'];

    print("$product_type<br>n");


    $prod_query = "select product_id, product_name from PRODUCTS where product_name like '%$search_text%' and product_type = '$product_type' LIMIT 3";
    $prod_result = mysql_query($prod_query);

    $rows = mysql_num_rows($prod_result);

    while($prod_row = mysql_fetch_array($prod_result))
    {
    $product_id = $prod_row['product_id'];
    $product_name = $prod_row['product_name'];

    if($rows == 0)
    {
    print("There are no matches in this product_type.n");

    }
    elseif($rows > 0)
    {
    print("&nbsp;&nbsp;&nbsp;$product_name<br>n");
    }

    }



    }

    }
  2. #2
  3. No Profile Picture
    PAV
    Guest
    Devshed Newbie (0 - 499 posts)
    In essence it's OK, but you should place the if/else outside the fetching of the results:

    $rows = mysql_num_rows($prod_result);

    if($rows == 0)
    {
    print("There are no matches in this product_type.n");

    }
    elseif($rows > 0)
    {
    while($prod_row = mysql_fetch_array($prod_result))
    {
    $product_id = $prod_row['product_id'];
    $product_name = $prod_row['product_name'];

    print(" $product_name<br>n");
    }

    }

Similar Threads

  1. Mysql problem.
    By Nik in forum MySQL Help
    Replies: 54
    Last Post: December 21st, 2006, 06:02 PM
  2. Starting MySQL
    By bwreath in forum MySQL Help
    Replies: 1
    Last Post: January 20th, 2004, 11:17 PM
  3. How PHP deals with MySQL Empty set
    By ultralight in forum PHP Development
    Replies: 5
    Last Post: January 19th, 2004, 08:33 AM
  4. MySQL SET datatype - Extract Exact Match?
    By rxsid in forum PHP Development
    Replies: 1
    Last Post: January 18th, 2004, 05:52 PM

IMN logo majestic logo threadwatch logo seochat tools logo