Advertisement
Guest User

Class week search

a guest
Sep 28th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <?php      
  2.     //Set your timezone
  3.     $timezone = date_default_timezone_set('UTC');
  4.    
  5.     //Pull our date in integer form, easy way to search our array.
  6.     //$intDay = date('w',strtotime("Wednesday")); //Test code to change the date
  7.     $intDay = date('w');
  8.  
  9.  
  10.  
  11.     /* Now we need a way to cycle the classes
  12.     ** And maybe the times too, why not?
  13.     ** So lets construct a 2D array storing all the information
  14.     */
  15.  
  16.     $classArray = array(
  17.         //Monday
  18.         array ( "Class37830"),
  19.         //Tuesday
  20.         array ("Class27800","Class28930"),
  21.         //Wednesday
  22.         array ("Class37830"),
  23.         //Thursday     
  24.         array (),
  25.         //Friday
  26.         array ("Class16700","Class17800","Class18900"),
  27.         //Saturday
  28.         array (),
  29.         //Sunday
  30.         array ()
  31.     );
  32.        
  33.     /* Now we have our data stored in an array count of 7 (for each day of the week) and we have our day
  34.     ** numeric number, ie. 0 = Monday, 1 = tuesday.. 6 = sunday.
  35.     ** we can just do a for loop, check the contents of the 2D array on that date, and if it exisits,
  36.     ** just echo it out
  37.     */
  38.        
  39.     for ($i = $intDay; $i < $intDay + 7; $i++){
  40.         /*This counter will loop above our array length, but we still want 7 days..
  41.         ** So we set $c to be our indexer for our array to give us the final, correct date value.
  42.         */
  43.         $c = ($i <= 7) ? $i : $i - 7;
  44.         //Check if our day has any classes
  45.         if (!empty($classArray[$c])){
  46.             //It does, so let's alert the user which date it is.
  47.             echo "<b><p>Class for ".date('l', strtotime("Monday +$i days")). "</p></b>";
  48.             //Then cycle the array and print out the class information
  49.             foreach($classArray[$c] as $output){
  50.                 echo "<li>".$output."</li>";
  51.             }
  52.         }
  53.     }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement