rn14 Posted November 17, 2008 Share Posted November 17, 2008 Could anybody tell me why the if statement below will not work? And how to get it to work? The value of meals changes and what i want to happen is when it increases by 20 for the value of people to increase by one. Thanks in advance. if ($meals = "20") $people = "1"; elseif ($meals = "40") $people = "2"; $peop = $people; echo $peop; Link to comment https://forums.phpfreaks.com/topic/133135-simple-if-statement/ Share on other sites More sharing options...
trq Posted November 17, 2008 Share Posted November 17, 2008 = is the assignment operator, your looking for == (a comparison operator). Also, numbers are not surrounded by quotes in php. Link to comment https://forums.phpfreaks.com/topic/133135-simple-if-statement/#findComment-692374 Share on other sites More sharing options...
flyhoney Posted November 17, 2008 Share Posted November 17, 2008 <?php if ($meals == 20) { $people = 1; } else if ($meals == 40) { $people = 2; } echo $people; ?> Link to comment https://forums.phpfreaks.com/topic/133135-simple-if-statement/#findComment-692384 Share on other sites More sharing options...
flyhoney Posted November 17, 2008 Share Posted November 17, 2008 also: $people = ceil($meals/20); Link to comment https://forums.phpfreaks.com/topic/133135-simple-if-statement/#findComment-692386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.