SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    boiler up blackdog's Avatar
    Join Date
    Jul 2002
    Location
    Purdue
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to tell if query returns 0 rows

    I have a page that runs a query that will very possibly return 0 rows. If it returns 0 rows I want it to say "None found" but if there are rows returned it needs to display them. How can I tell if the result returns 0 rows?

    I've tried the following:

    PHP Code:
    $result=mysql_query($query);
    $c=count($result);
    if(
    $c==0)
    {
    echo
    'None found';

    and...

    PHP Code:
    if($result=='')
    {
    echo
    'None found';
    }| 
    neither worked. anyone know what will work? thanks!

  2. #2
    SitePoint Addict CrabbyX's Avatar
    Join Date
    Aug 2004
    Location
    England, UK
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $result=mysql_query($query);
    $c=mysql_num_rows($result);
    if(
    $c==0)
    {
    echo
    'None found';

    michael.Crabbe

  3. #3
    boiler up blackdog's Avatar
    Join Date
    Jul 2002
    Location
    Purdue
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    worked perfectly! thanks


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
  •