Jump to content

Recommended Posts

Hello there!

 

I've been at this for too long! I've got a normal calendar at the side of my website that works fine, however i would like one that shows the next 7 days starting at today. I have an image here that kind of shows what i want...

 

110yvk3.png

 

So it will show the next 7 days starting with today, and going into the next month if todays date is the 30th etc.

 

Could anybody please help me? :\

Link to comment
https://forums.phpfreaks.com/topic/237544-calendar-help/
Share on other sites

<?php
$cDay = date("d");
echo '<tr>';
for ($i=$cDay; $i<($cDay+7); $i++) {
echo '<td width="14%" class="calender1a"><b>Sunday</b></td>';
}
echo '</tr>';

echo '<tr>';
for ($i=$cDay; $i<($cDay+7); $i++) {
echo '<td width="14%" class="calender2a">Raid<br />Time<br />Picture?</td>';
}
echo '</tr>';
?>

 

Thats the code so far, the only thing i can't do is make it show the day names at the top...

Link to comment
https://forums.phpfreaks.com/topic/237544-calendar-help/#findComment-1220664
Share on other sites

Loading my page with that code completely crashes my web browser :L No idea why!

Crashes it or shows a blank page?

 

It works for me (ff3).  Output (of course I don't have your CSS class):

ThursdayFridaySaturdaySundayMondayTuesdayWednesday

 

If it's blank, try turning on error reporting:

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
https://forums.phpfreaks.com/topic/237544-calendar-help/#findComment-1220677
Share on other sites

Comments in the code (check out date for date formatting, the "l"):

//Gets the current day (Thursday)
$cDay = strtotime(date("d"));

//Loop through 1-7, to increment each day of the week
for($i=1; $i{
   //"l" is just the format for date (A full textual representation of the day of the week)
   //strtotime takes the current day ($cDay) and adds +1 ($i) each loop, adding a day
   echo '' . date("l", strtotime('+'.$i.'day', $cDay)) . ' $i -> +' . $i . 'day
';
}

?>

 

Output:

Thursday $i-> +1day
Friday $i-> +2day
Saturday $i-> +3day
Sunday $i-> +4day
Monday $i-> +5day
Tuesday $i-> +6day
Wednesday $i-> +7day

 

Hope that makes sense.

Link to comment
https://forums.phpfreaks.com/topic/237544-calendar-help/#findComment-1220687
Share on other sites

strtotime converts a date in string format to a unix timestamp.

 

the for loop pretty much makes sure you loop 7 times

 

strtotime('+'.$i.'day', $cDay) will translate to strtotime('+1/2/3... day', currentTimestamp) which will return a unix timestamp 1,2,3,etc days from now.

 

The date('l') returns the textual day of the week from that timestamp.

 

The only thing I don't like about this function is that date is a notoriously slow function, from what I remember. It could be sped up, potentially with something like this

 

$today = date('l');
$days = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
$split = array_search($today,$days);
$days = array_merge(array_slice($days,$split),array_slice($days,0,$split));

echo implode(', ', $days);

 

I'm honestly not sure if it's much faster that Maqs script, which is much more simple in design. His will be much better if you also want to echo the day of the month.

Link to comment
https://forums.phpfreaks.com/topic/237544-calendar-help/#findComment-1220697
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.