Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //I'm doing this function so I don't have to keep typing the query over again
- function getCalendarDay($day,$spaces){
- global $db;
- $count = $db->query("SELECT day FROM users WHERE day = ?",array($day))->count();
- $remaining = $spaces - $count;
- //if you never want it to show negative numbers, use this,otherwise comment it out.
- if($remaining < 0 ){$remaining = 0;}
- return $remaining;
- }
- $spaces = 6; //how many spaces do you have available?
- //Doing this so I don't have to keep typing the days of the week
- $days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
- $times = ['11:00','12:00','13:00','14:00','15:00','16:00','17:00',]
- ?>
- <table class="table">
- <thead>
- <tr>
- <th>Day</th><th>Time</th><th>Activity</th><th>Spots Available</th>
- </tr>
- <tbody>
- <?php
- //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
- //We are going to use that to get the cooresponding time from the times array.
- foreach($days as $k=>$v){ ?>
- <tr>
- <td><?php echo $v;?></td>
- <td><?php echo $times[$k];?></td>
- <td>Yoga</td>
- <td><?php echo getCalendarDay($v,$spaces);?></td>
- </tr>
- <?php } ?>
- </tr>
- </tbody>
- </tbody>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement