Advertisement
Guest User

Untitled

a guest
Jan 4th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 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. ?>
  17. <table class="table">
  18. <thead>
  19. <?php
  20. //Setup the column headers
  21. foreach($days as $day){ ?>
  22. <th><?=$day?></th>
  23. <?php } ?>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <?php
  28. //do the rows and get the count
  29. foreach ($days as $day) { ?>
  30. <td><?php echo getCalendarDay($day,$spaces);?></td>
  31. <?php } ?>
  32. </tr>
  33. </tbody>
  34. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement