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...
If exist else..
Moderator: General Moderators
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
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
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
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");- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
more likesomeberry 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");
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');
}