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.
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
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.)
I managed to find this somewhere on these massive forums a while back
<?php
// We are gonna loop each day of the week
for($dayofweek = 0; $dayofweek < 7; $dayofweek++)
{
// echo our column opening
echo '';
// 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 ‘’;
}
?>
Feel free to edit the code as required (e.g. removing <td>/<tr> is not in table, etc.)
<?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”.
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>';
}
?>