Julian Posted April 17, 2008 Share Posted April 17, 2008 Hi guys I'm making a calendar for my web page, but I want to show the days as events and link those events to the correspondent page. I have this to get the days: $sd = '2008-04-01'; $ed = '2008-04-15'; for ($z=strtotime($sd);$z<strtotime($ed);$z+=86400) echo date('d',$z); This works excellent to get the days between to dates. Here's the code for the links in the calendar: $days = array(); $c = 0; $d = ?????;//Here's should be days I got from the previous code $l = 'users.php?day='.$d.'&month='.$month.'&year='.$year; $days[$d][] = $l; echo generate_calendar(date('Y', $time), date('n', $time), $days, 1, NULL, 0, $pn); setlocale(LC_TIME, $oldlocale); I have to create a loop on $d in order to reflect all the days in between the dates. Any help will be highly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/ Share on other sites More sharing options...
Zhadus Posted April 17, 2008 Share Posted April 17, 2008 I believe the following code would build an array with all the days between the event dates. $sd = '2008-04-01'; $ed = '2008-04-15'; for ($z=strtotime($sd);$z<strtotime($ed);$z+=86400) $dArray[] = date('d',$z); Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519503 Share on other sites More sharing options...
p2grace Posted April 17, 2008 Share Posted April 17, 2008 He's already doing that. I believe what he wants to know is how to show events during that time. You'd have to create a database table that saves a begin date and an end date. Then query the table before generating the calendar and save all of the upcoming events for the given month into an array. Then while you're looping through the days of the month check to see if it is within the range of one of the events from the array. If it is show the event. Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519523 Share on other sites More sharing options...
Julian Posted April 17, 2008 Author Share Posted April 17, 2008 Thanks guys I already have everything on the database, start_date and end_date, I just put a sample code not including the database query to simplify my request. $days = array(); $c = 0; $d = ?????;//Here's should be days I got from the previous code $l = 'users.php?day='.$d.'&month='.$month.'&year='.$year; $days[$d][] = $l; echo generate_calendar(date('Y', $time), date('n', $time), $days, 1, NULL, 0, $pn); setlocale(LC_TIME, $oldlocale); How can I call the array ($dArray[]) into this script? or convert $dArray[] to a variable... Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519534 Share on other sites More sharing options...
p2grace Posted April 17, 2008 Share Posted April 17, 2008 Instead of echoing out the days just save them to an array then do a foreach on the array to start looping through them. Is that what you're asking? Otherwise could you elaborate? Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519537 Share on other sites More sharing options...
Julian Posted April 17, 2008 Author Share Posted April 17, 2008 Hi Yes that is what I'm looking for. How can translate that into a scrip? Regards Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519575 Share on other sites More sharing options...
p2grace Posted April 17, 2008 Share Posted April 17, 2008 Do this to create your array: <?php $sd = '2008-04-01'; $ed = '2008-04-15'; $days = array(); for ($z=strtotime($sd);$z<strtotime($ed);$z+=86400){ echo date('d',$z); $days [] = $z; } //Then foreach through it foreach($days as $key => $day){ $d = $day; $l = 'users.php?day='.$d.'&month='.$month.'&year='.$year; $days[$key]['l'] = $l; echo generate_calendar(date('Y', $time), date('n', $time), $days, 1, NULL, 0, $pn); setlocale(LC_TIME, $oldlocale); } ?> Something simple like that should do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519581 Share on other sites More sharing options...
Julian Posted April 17, 2008 Author Share Posted April 17, 2008 Thanks dude, being great help... I get this error: Warning: Cannot use a scalar value as an array in /home/redcul/public_html/php/calendario.php on line 60 Line 60: $days[$key]['l'] = $l; Sorry for ask but what for is ['l']? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519626 Share on other sites More sharing options...
p2grace Posted April 17, 2008 Share Posted April 17, 2008 Actually just remove that line, I just changed what you had originally to one that wouldn't interfere with my array. Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519628 Share on other sites More sharing options...
Julian Posted April 17, 2008 Author Share Posted April 17, 2008 Hi thanks again, but the code isn't workin, but gave me a hint. I modified the code a little bit but the problem I have now i that I can't reset the array. It's supposed to start at 01 not at 10. Bellow the calendar I echoed the array. Working example at: http://www.redcultura.com/php/calendario.php Here's the code: $sd = '2008-04-01'; $ed = '2008-04-15'; $days = array(); for ($z=strtotime($sd);$z<strtotime($ed);$z+=86400) $day[] = date('d',$z); $days = array(); $c = 0; foreach($day as $value){ $c++; $d = $value; $l = 'users2.php?dia='.$d.'&mes='.$mes.'&ano='.$ano; $days[$d][] = $l; } echo generate_calendar(date('Y', $time), date('n', $time), $days, 1, NULL, 0, $pn); setlocale(LC_TIME, $oldlocale); Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519657 Share on other sites More sharing options...
p2grace Posted April 17, 2008 Share Posted April 17, 2008 Try this: <?php $sd = '2008-04-01'; $ed = '2008-04-15'; $days = array(); for ($z=strtotime($sd);$z<strtotime($ed);$z+=86400) $day[] = date('d',$z); $days = array(); $c = 0; foreach($day as $value){ if($c == 09){ $c = 01; }else{ $c++; } $d = $value; $l = 'users2.php?dia='.$d.'&mes='.$mes.'&ano='.$ano; $days[$d][] = $l; } echo generate_calendar(date('Y', $time), date('n', $time), $days, 1, NULL, 0, $pn); setlocale(LC_TIME, $oldlocale); ?> Is this what you want it to do? Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519664 Share on other sites More sharing options...
Julian Posted April 17, 2008 Author Share Posted April 17, 2008 Hi No, if you check the $sd and $ed values, the numbers should start on 01, this will depend on the $sd value. If I foreach ($day as $value) { echo "Days: $value . 'This day should be in the calendar'<br />\n"; } I get all the days in the array. But this is not showing on the calendar script. I think here's the problem: $days = array(); $c = 0; Thanks for looking. Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519672 Share on other sites More sharing options...
p2grace Posted April 17, 2008 Share Posted April 17, 2008 If I had to guess, it's probably because the calendar array isn't saving the array as "01" it's saving it as "1" so it doesn't think there's an event for that day. Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519678 Share on other sites More sharing options...
Julian Posted April 17, 2008 Author Share Posted April 17, 2008 If I echo the array it shows the 01 -02 ..... Here's an example: http://www.redcultura.com/php/calendario.php Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519682 Share on other sites More sharing options...
Julian Posted April 17, 2008 Author Share Posted April 17, 2008 Hi guys Thanks for the help. Now I finished the code. I realized that the problem was in how I was calling the date format. Changed 'd' for 'j' solved the problem. Regards Quote Link to comment https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/#findComment-519719 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.