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
Share on other sites

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

Link to comment
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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.