cupaball Posted February 12, 2009 Share Posted February 12, 2009 Hi ALL: I am trying to pull the weekend dates based on the current day and pull some information based on the weekend. When $daynum = 4 the code works but when I change $daynum = 5 the I get nuthin. Can anyone help? <?php require("connection.php"); $daynum = '5'; if ($daynum == '4') { $date1 = date("Y-m-d", strtotime("+1 days")); $date2 = date("Y-m-d", strtotime("+3 days")); $q = " SELECT `tb_events`.`date`, `tb_events`.`event_title`, `tb_events`.`info` FROM `tb_events` WHERE (`tb_events`.`date` >= DATE_FORMAT('$date1' , '%Y-%m-%d')) AND (`tb_events`.`date` <= DATE_FORMAT('$date2' , '%Y-%m-%d')) "; $result = $mysqli->query($q) or die($mysqli_error($mysqli)); if($result) { while($row = $result->fetch_object()) { $event = $row->event_title; $date = $row->date; $info = $row->info; print'<h3>Event: '.$event.'</h3>'; print'<p>Date: '.$date.'</p>'; print'<p>Event Info: '.$info.'</p>'; } } else if ($daynum == '5') { $date1 = date("Y-m-d"); $date2 = date("Y-m-d", strtotime("+2 days")); $q = " SELECT `tb_events`.`date`, `tb_events`.`event_title`, `tb_events`.`info` FROM `tb_events` WHERE (`tb_events`.`date` >= DATE_FORMAT('$date1' , '%Y-%m-%d')) AND (`tb_events`.`date` <= DATE_FORMAT('$date2' , '%Y-%m-%d')) "; $result = $mysqli->query($q) or die($mysqli_error($mysqli)); if($result) { while($row = $result->fetch_object()) { $event = $row->event_title; $date = $row->date; $info = $row->info; print'<h3>Event: '.$event.'</h3>'; print'<p>Date: '.$date.'</p>'; print'<p>Event Info: '.$info.'</p>'; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/ Share on other sites More sharing options...
alphanumetrix Posted February 12, 2009 Share Posted February 12, 2009 You should break it up into functions to make it cleaner. The problem is you put this: else if ($daynum == '5') { else if won't execute how you wrote it (you put a space in between). This is how it needs to be done: elseif ($daynum == '5') { Also, you don't need to put ' around your 5: elseif ($daynum == '5') { Since its a numeral, you can just leave them off: elseif ($daynum == 5) { hope this helps! Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/#findComment-760871 Share on other sites More sharing options...
gevans Posted February 12, 2009 Share Posted February 12, 2009 One of your curly brackets is in the wrong place, you should find it no worries, turn your error display on when testing Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/#findComment-760874 Share on other sites More sharing options...
gevans Posted February 12, 2009 Share Posted February 12, 2009 You should break it up into functions to make it cleaner. The problem is you put this: else if ($daynum == '5') { else if won't execute how you wrote it (you put a space in between). This is how it needs to be done: elseif ($daynum == '5') { Also, you don't need to put ' around your 5: elseif ($daynum == '5') { Since its a numeral, you can just leave them off: elseif ($daynum == 5) { hope this helps! else if will work with a space The problem is with his placement of curly brackets Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/#findComment-760877 Share on other sites More sharing options...
cupaball Posted February 12, 2009 Author Share Posted February 12, 2009 It was def the curly bracket. Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/#findComment-760884 Share on other sites More sharing options...
cupaball Posted February 12, 2009 Author Share Posted February 12, 2009 Oh and how do i turn on error display? And that is great idea to turn into functions. I will start working on it. Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/#findComment-760887 Share on other sites More sharing options...
gevans Posted February 12, 2009 Share Posted February 12, 2009 ini_set('display_errors', 1); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/#findComment-760891 Share on other sites More sharing options...
alphanumetrix Posted February 13, 2009 Share Posted February 13, 2009 that's weird... php.net says "elseif" doesn't work with a space... sorry, i couldn't help.... Link to comment https://forums.phpfreaks.com/topic/145003-if-else-if-statement-issue/#findComment-761262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.