SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Screw City
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to determine if query returns info...

    Hello...
    When querying a database, how can you tell whether or not the query actually returns any information? Possibly to output a notice that no information was returned.

    thanks,
    sod

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $numResults = mysql_num_rows($result);
    if($numResults == 0){
    blah blah
    }else{
    blah blah
    }
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Member
    Join Date
    Feb 2001
    Location
    Screw City
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot...that's exactly what I needed. I had no idea that function existed..guess I should go on php.net more often..

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2001
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually use this instead...is it a problem?

    if ($result)
    {
    blah blah
    }
    else
    blah

  5. #5
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works for me, although the former example is possibly more correct.
    Travis Burnside
    travis@qwk.net

    Free monitoring for your web site - http://www.qwkmon.com

  6. #6
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    d-net your code will tell you if the query was successfully executed. It can be successfully executed and still return 0 results. Basically what you're doing is used for error handling.

    The code I posted is what you'd use to see if the query returned any results at all, assuming it was successfully executed.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums


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
  •