SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Test for No Results

    Hi All

    I have a script which looks at properties in a MySQL Database when there are no properties available in the search I want to show sme text (shown below in an echo statement)

    PHP Code:

    $props 
    = @mysql_query($select $from $where $bywhat);
    if (!
    $props) {
      echo 
    '</table>';
      exit(
    '<p>Error retrieving properties from database!<br />'.
          
    'Error: ' mysql_error() . '<p>Try Later</p>');
    }

    while (
    $properties mysql_fetch_array($props)) {
      
    $id $properties['id'];
      
    $PropertyType $properties['PropertyType'];
    }

    if (!
    $id){
    echo
    "nothing in the search";

    The actual script hs far more entries but I have cut it down for the purposes here.

    The problem is I cant get my head around how to test if the result list has returned nothing. I have tried if the $id is NOT ie false show the message but it doesnt work

    Any help? Guys!!

    Cheers

    Keith

  2. #2
    HardCoder md_irfan_amu's Avatar
    Join Date
    May 2005
    Location
    Asia
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    while ($properties = mysql_fetch_array($props)) {
    $id = $properties['id'];
    $PropertyType = $properties['PropertyType'];
    }

    if (!$id){
    echo"nothing in the search";
    }

    Use this
    $rowCount = mysql_num_rows($props);

    this will give the no of rows returns your select command...
    now you can apply
    if($rowCount>0)
    {
    $properties = mysql_fetch_array($props))
    $id = $properties['id'];
    $PropertyType = $properties['PropertyType'];
    }
    else
    {
    echo("no properties");
    }



    other way
    if(mysql_num_rows($props)>0)
    {
    $properties = mysql_fetch_array($props))
    $id = $properties['id'];
    $PropertyType = $properties['PropertyType'];

    }
    else
    {
    echo("no properties");

    }


    I hope u got ur solution

  3. #3
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Thanks friend!!

    Works a treat. Your a genious! Thats been bothering me all night!

    Cheers again

    Keith

    Muchos respect!!!!!

  4. #4
    HardCoder md_irfan_amu's Avatar
    Join Date
    May 2005
    Location
    Asia
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no problem its ok

    Regards
    Irfan
    Find Tutors Easyway to get connect with your tutor in india


Bookmarks

Posting Permissions

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