Jump to content

Recommended Posts

Posted

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

  • Administrators
Posted

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.

Posted

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

Posted

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

  • Like 1
Posted

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

Posted

Works exactly like it is supposed to, thanks! B)

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

Posted

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".

  • Like 2
  • Administrators
Posted

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>';
}
?>

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...