AJLX Posted July 29, 2012 Share Posted July 29, 2012 Hello Guys, I'm currently working on this swerv.ajlx.co.uk project. When some one clicks on a date on the calendar it brings up a table to allow bookings. However on weekends I need to be able to display a different table as the booking times are different. Can anyone think of a way I might be able to do this? I'm not asking for you to code it for me- but some hints, suggestions and ideas would be lovely! I'm currently working on the coding, and not the aesthetics- so ignore the obvious css issues! Let me know if you need any code snippets! login: chicken password: goat Regards, Andy Jones Quote Link to comment https://forums.phpfreaks.com/topic/266411-calendar-hints/ Share on other sites More sharing options...
NLT Posted July 29, 2012 Share Posted July 29, 2012 I'm not sure if I read it right, but can't you use an if statement, so like: $day = "Saturday"; if($day == "Saturday" || $day == "Sunday") { // Weekend table } else { // Weekday } Quote Link to comment https://forums.phpfreaks.com/topic/266411-calendar-hints/#findComment-1365249 Share on other sites More sharing options...
AJLX Posted July 29, 2012 Author Share Posted July 29, 2012 Hi there, It is slightly more complicated than that! The Calendar table is populated with a loop: $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']-1; $new_month = ($monthNames[$cMonth-1]); for ($i=0; $i<($maxday+$startday); $i++) { $day = ($i - $startday + 1); if(($i % 7) == 0 ) echo "<tr>"; if($i < $startday) echo "<td></td>"; else echo "<td align='center' valign='middle' height='20px'><a href=",'/index.php' . "?day1=" .$day. "&month1=". $new_month . "&year1=" . "$cYear>". ($i - $startday + 1) . "</a></td>"; if(($i % 7) == 6 ) echo "</tr>"; } The numbers that populate the table aren't dates. I guess I need to convert these numbers (and the month) back into a readable date format that I can then do an If statement on? Any ideas on the best way to do this? Regards, Andy Jones Quote Link to comment https://forums.phpfreaks.com/topic/266411-calendar-hints/#findComment-1365252 Share on other sites More sharing options...
PFMaBiSmAd Posted July 29, 2012 Share Posted July 29, 2012 I need to be able to display a different table as the booking times are different. Your code in index.php would take the requested date made up from the day1, month1, and year1 get parameters, determine if that date it is a weekday or weekend day, and output the correct booking table. strtotime and date can be used together to get the day of week numerical or textual representation for the date. Quote Link to comment https://forums.phpfreaks.com/topic/266411-calendar-hints/#findComment-1365253 Share on other sites More sharing options...
xyph Posted July 29, 2012 Share Posted July 29, 2012 If you want to limit your date calls to save speed, simply find the first Saturday of the month. $first_saturday = getdate(strtotime('this saturday', $timestamp)); Then, use a loop to populate an array with the weekend dates $weekend_dates = array(); for($i = $first_saturday['mday']; $i <= $maxday; $i += 7 ) $weekend_dates = array_merge($weekend_dates, array($i, $i+1)); print_r($weekend_dates); If the month ends on a Saturday, you'll have an extra non-existent day on the end of the array, but it doesn't matter much because it will never get checked against. Quote Link to comment https://forums.phpfreaks.com/topic/266411-calendar-hints/#findComment-1365260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.