...

View Full Version : empty result



yebaws
03-23-2009, 11:47 PM
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....

Old Pedant
03-24-2009, 12:26 AM
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.

yebaws
03-24-2009, 04:54 PM
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.":)

Fumigator
03-24-2009, 08:29 PM
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.

yebaws
03-24-2009, 08:34 PM
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

Old Pedant
03-24-2009, 09:16 PM
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 />

Fumigator
03-24-2009, 09:22 PM
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...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum