I have a mysql database called menus. I am able to query my database to obtain a recordset accordingly. I do NOT want to write a query for each season. My problem: I want to write a php if statement within body to echo a message if the season field CONTAINS 2.
table menu
id | item (varcar) | season (set)
1 | fresh lemonade | 2,3
2 | smoothie | 2
3 | cafe latte | 4
My query works fine
mysql_select_db($database_rest, $rest); $query_menus = "SELECT * FROM menus";
$menus = mysql_query($query_menus, $rest) or die(mysql_error());
$row_menus = mysql_fetch_assoc($menus);
$totalRows_menus = mysql_num_rows($menus);
I can write a php if to work where recordset field = 2 that works.
<?php echo $row_menus['item']; ?>: <?php
if (@$row_menus['season'] == 1)
{
echo "Winter";
}
else if (@$row_menus['season'] == 2)
{
echo "Spring";
}
else if (@$row_menus['season'] == 3)
{
echo "Summer";
}
else if (@$row_menus['season'] == 4)
{
echo "Fall";
}
?>
Result Shows:
fresh lemonade: Spring
smoothie: Spring
cafe latte: Fall
I want to write php so that if season CONTAINS 2 (example: if (@$row_menus['season'] CONTAINS 1) echo Spring, etc for each. so that result would look like this:
fresh lemonade: Spring
fresh lemonade: Summer
smoothie: Spring
cafe latte: Fall
mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which.