Jump to content

[SOLVED] Converto to an array of values


Julian

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/101566-solved-converto-to-an-array-of-values/
Share on other sites

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.

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.

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.

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);

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.