SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error out if no results

    I would like to do a bit of error trapping on a little script that I have that takes a few fields from a mysql db and displays them on a page... its called with SSI.

    I am selecting the data based on a field "aid". If aid is an invalid number (not in the db), I would like to display a message.

    Here's my basic select so far:

    $result = mysql_query("SELECT * FROM homes WHERE featured = 'Y' AND owner=$aid;",$link);
    while ($a_row =mysql_fetch_array ($result) )
    {
    ##display some stuff
    }

    Any suggestions are greatly appreciated.

    Thanks.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem try this:
    PHP Code:
    $result mysql_query("SELECT * FROM homes WHERE 
    featured = 'Y' AND owner=
    $aid;",$link); 
    if(
    mysql_num_rows($result) > 0) {
        while (
    $a_row =mysql_fetch_array ($result) ) 
    {  
            
    ##display some stuff 
            

        }
    else {
        print 
    "Some error message";
        } 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet! Simple and to the point.

    Thanks!
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I'm being REALLY picky here, but I use this:

    Code:
    if(mysql_num_rows($result)) {
    The less-than/greather-than signs are not necessary, unless I'm missing something. Any non-zero value will return true...that is, unless I'm making a fool of myself, and Freddy is just waiting to pounce all over me again. He's quite good at it! After all, that's what cats do.


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
  •