Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. //I'm doing this function so I don't have to keep typing the query over again
  3. function getCalendarDay($day,$spaces){
  4. global $db;
  5. $count = $db->query("SELECT day FROM users WHERE day = ?",array($day))->count();
  6. $remaining = $spaces - $count;
  7. //if you never want it to show negative numbers, use this,otherwise comment it out.
  8. if($remaining < 0 ){$remaining = 0;}
  9. return $remaining;
  10. }
  11.  
  12.  
  13. $spaces = 6; //how many spaces do you have available?
  14. //Doing this so I don't have to keep typing the days of the week
  15. $days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
  16. $times = ['11:00','12:00','13:00','14:00','15:00','16:00','17:00',]
  17. ?>
  18. <table class="table">
  19. <thead>
  20. <tr>
  21. <th>Day</th><th>Time</th><th>Activity</th><th>Spots Available</th>
  22. </tr>
  23. <tbody>
  24.  
  25. <?php
  26. //When you do k=>v you get the key of the array as on 0,1,2 and the value as in Mon, tue Wed
  27. //We are going to use that to get the cooresponding time from the times array.
  28. foreach($days as $k=>$v){ ?>
  29. <tr>
  30. <td><?php echo $v;?></td>
  31. <td><?php echo $times[$k];?></td>
  32. <td>Yoga</td>
  33. <td><?php echo getCalendarDay($v,$spaces);?></td>
  34. </tr>
  35.  
  36. <?php } ?>
  37. </tr>
  38. </tbody>
  39. </tbody>
  40. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement