Jump to content

Calendar Hints


AJLX

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.