Page 1 of 1
If exist else..
Posted: Fri Apr 14, 2006 6:51 am
by Qaid
Hi,
I run MySQL with a database with a table called toys.
The table contains data equals to 1 or 0.
My question are, is it possible to make a query that ask if the table contains 1, then echo Yes!. But if the table contain 0 then it will post No!.
Thank you very much!
Best Regards...
Posted: Fri Apr 14, 2006 7:12 am
by rubberjohn
if that is all you need the query to do, just do a normal query where that column data = 1 if the query returns a value echo yes if not echo no
alternatively just do a query that select all the data in the table with no conditions set and test the returned results
choose which ever one suits your needs
Posted: Fri Apr 14, 2006 7:35 am
by someberry
Something like...
Code: Select all
$rs = mysql_query("SELECT * FROM `toys` WHERE `your_field` = 1") or die(mysql_error());
echo(mysql_num_rows($rs) > 0 ? "Yes" : "No");
Posted: Sat Apr 15, 2006 1:22 pm
by Qaid
1.
$rs = mysql_query("SELECT * FROM `toys` WHERE `your_field` = 1") or die(mysql_error());
2.
3.
echo(mysql_num_rows($rs) > 0 ? "Yes" : "No");
This will post "Yes" with the data 1, 0 or empty...
Help?

Posted: Sat Apr 15, 2006 1:51 pm
by John Cartwright
someberry wrote:Something like...
Code: Select all
$rs = mysql_query("SELECT * FROM `toys` WHERE `your_field` = 1") or die(mysql_error());
echo(mysql_num_rows($rs) > 0 ? "Yes" : "No");
more like
Code: Select all
$rs = mysql_query("SELECT `your_field` FROM `toys`") or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo ($row['your_field'] == 1 ? 'Yes' : 'No');
}