CitationCJ Posted April 17, 2016 Report Posted April 17, 2016 Hey guys I tried using this code to display an image on the day the flight is flown: <?php if($route->daysofweek == 1) { echo'imagehere' ; } ?> Now, if I want to display a empty entry if there is no flight on that day, I will use this: <?php if($route->daysofweek == 1) { echo'imagehere' ; } else { echo''; } ?> For some reasons, this isnt working and its either showing nothing or the image shows up even though there is no flight on Day 1. Does anyone have a quick fix for this? Thanks in advance and have a good sunday. Pierre Quote
Administrators simpilot Posted April 17, 2016 Administrators Report Posted April 17, 2016 It is because $route->daysofweek can be anything from a single digit to 01234567. The only time it would only be "1" would be if it was flown on Mondays only. You will have to break it apart and then do your comparison. Quote
CitationCJ Posted April 17, 2016 Author Report Posted April 17, 2016 Thanks simpilot for the answer. What I am trying to do is having a table showing MON-SUN and if the route is flown on Monday (1) only, an image will appear in the respective field under MON and the rest of the table will show nothing. So if a route is flown on MON and TUE, the image will appear under MON and TUE only Thanks in advance Pierre Quote
web541 Posted April 17, 2016 Report Posted April 17, 2016 Hey CitationCJ, I managed to find this somewhere on these massive forums a while back <tr> <?php // We are gonna loop each day of the week for($dayofweek = 0; $dayofweek < 7; $dayofweek++) { // echo our column opening echo '<td>'; // Check if $i (the current day of week) exists if(substr_count($route->daysofweek, $dayofweek) > 0) { // there is a flight for sunday , so echo that plane icon out echo 'imagehere'; } // Close that column echo '</td>'; } ?> </tr> Feel free to edit the code as required (e.g. removing <td>/<tr> is not in table, etc.) Pseudo code I believe 1 Quote
CitationCJ Posted April 18, 2016 Author Report Posted April 18, 2016 Hey CitationCJ, I managed to find this somewhere on these massive forums a while back <tr> <?php // We are gonna loop each day of the week for($dayofweek = 0; $dayofweek < 7; $dayofweek++) { // echo our column opening echo '<td>'; // Check if $i (the current day of week) exists if(substr_count($route->daysofweek, $dayofweek) > 0) { // there is a flight for sunday , so echo that plane icon out echo 'imagehere'; } // Close that column echo '</td>'; } ?> </tr> Feel free to edit the code as required (e.g. removing <td>/<tr> is not in table, etc.) Pseudo code I believe Thank you! I will give this one a try when I get back home. Cheers, Pierre Quote
CitationCJ Posted April 18, 2016 Author Report Posted April 18, 2016 Works exactly like it is supposed to, thanks! Now I only need to change sunday to monday (i.e. 7->0 in php). I tried using the code that already comes with phpvms, however the results still show up on the wrong days. $route->daysofweek = str_replace('7', '0', $route->daysofweek); Best, Pierre Quote
web541 Posted April 18, 2016 Report Posted April 18, 2016 It has worked for me <?php // We are gonna loop each day of the week for($dayofweek = 0; $dayofweek < 7; $dayofweek++) { // echo our column opening echo '<td>'; $route->daysofweek = str_replace('7', '0', $route->daysofweek); // Check if $i (the current day of week) exists if(substr_count($route->daysofweek, $dayofweek) > 0) { // there is a flight for sunday , so echo that plane icon out echo 'imagehere'; } // Close that column echo '</td>'; } ?> By default, phpvms changes the days of week to 0123456 (0 = Sunday), If you've got Sunday by itself as "7", then use your code above and it should work. If it's still not showing as required, then check the daysofweek column in your database and verify that the numbers are either "0123456" or "1234567". 2 Quote
Administrators simpilot Posted April 23, 2016 Administrators Report Posted April 23, 2016 I do not know what code you are running prior to the snippet but I think you would be better served by using explode and then in_array, maybe something like this; <?php $daysofweek = explode($route->daysofweek); // We are gonna loop each day of the week for($dayofweek = 0; $dayofweek < 7; $dayofweek++) { // echo our column opening echo '<td>'; // Check if $i (the current day of week) exists if(in_array($dayofweek, $daysofweek) { // there is a flight for this day , so echo that plane icon out echo 'imagehere'; } // Close that column echo '</td>'; } ?> 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.