Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: empty result

  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    empty result

    This must be a simple one, but I can't find the answer anywhere...

    How do I make a conditional statement based on an SQL query being empty?

    eg:

    select * from table where column = 'something'

    and then if the result is empty I want to echo "search returned no results". I can think of several ways to do it but they're not simple....

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Not a MySQL question.

    The answer depends on what server-side technology your are using: PHP, JSP, ASP, ASP.NET, CF, or whatever.

    I would *guess* you are using PHP, since you mentioned echo in your post. If so, this is really a PHP question.

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Not a MySQL question.

    The answer depends on what server-side technology your are using: PHP, JSP, ASP, ASP.NET, CF, or whatever.

    I would *guess* you are using PHP, since you mentioned echo in your post. If so, this is really a PHP question.
    Yes, I'm using PHP. Must point out, 'though - given your username - that in the forum list it states under this forum header:

    "PHP questions as they relate to mySQL should also be posted here."

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Since this is within the context of PHP then you can use the mysql_num_rows() function to easily check your resultset and echo your no results message if mysql_num_rows() is 0.

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    Since this is within the context of PHP then you can use the mysql_num_rows() function to easily check your resultset and echo your no results message if mysql_num_rows() is 0.
    excellent - thank you

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Huh. Nice catch, yebaws. Never noticed that about php/mysql before. Wonder why they did that?? If php/mysql is okay here, then why isn't asp/mysql or jsp/mysql or any other platform/mysql???? Kind of a bizarre exception to the general rule about topics.

    FWIW, I could have answered the question as it relates to ASP or ASP.NET or JSP. So if somebody had asked your question but related to those platforms, would I be wrong to answer it here??? (Not really asking you, just scratching my head.)

    But in any case, you have to admit you didn't explicitly SAY you were using PHP. I had to guess that based solely on your use of the word "echo." <grin />

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I'd say the average CF user in answer-seeker mode is using a webhost that provides PHP and MySQL as part of the hosting package, very new to web development (or any kind of development for that matter), and has never had access to closed-source tools such as JSP and ASP. (Maybe I'm projecting a bit because that comes close to my condition when I found CF)

    It naturally follows that users of this forum are using MySQL and PHP together, and I remember not long ago the PHP forum was getting slammed with MySQL questions so maybe the description was an attempt to funnel some of the question volume over to this forum.

    Just a guess...


  •  

    Posting Permissions

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