Jump to content

Recommended Posts

Hi,

 

I found a really useful calendar script here:  http://keithdevens.com/software/php_calendar

I'd like to use it as a summary of dates booked in a database list, i've been trying for hours to populate the following nested array dynamically but im not getting anywhere.

 

this is the array:

<?php 
    $days = array( 
        2=>array('/weblog/archive/2004/Jan/02','linked-day'), 
        3=>array('/weblog/archive/2004/Jan/03','linked-day'), 
        8=>array('/weblog/archive/2004/Jan/08','linked-day'), 
        22=>array('/weblog/archive/2004/Jan/22','linked-day'),  
    ); 
    echo generate_calendar(2004, 1, $days, 3, '/weblog/archive/2004/Jan'); 
?>

 

the number is the day number, the first key in the nested array is a hyperlink and the second is a CSS class.

 

for the time being i'll keep the link and the css class the same - so they will always have the same value.

 

so far i've created a connection to my server and created a while loop that does $days = $row['db_date'] and I can echo out the day numbers that I'm looking for - I just cannot figure out how to add the nested elements???

 

any advice would be greatly appreciated.

 

This is how I would do this.

your database loop goes here 
{
$link="/weblog/archive/".date("Y", strtotime($yourdatefield)."/".date("M",strtotime($yourdatefield))."/".sprintf("%02",date("d", strtotime($yourdatefield))); 
$class="linked-day"; 
$days[date("d", strtotime($yourdatefield))]['link']=$link; 
$days[date("d", strtotime($yourdatefield))]['cssclass']=$class; 

// OR if you don't need the keynames 

$days[date("d", strtotime($yourdatefield)))]=array($link,$class); 
}

excellent!!!

 

I'm almost there, I can get the desired result but only for one date in the list (the last date), I dont think the while loop is looping properly.

$link="/weblog/archive/";
$class="linked-day"; 
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{ 
$days = (array($row['gl_date']=>array($link,$class)));
}

 

If I echo out the array using print_r all the dates are there:

$link="/weblog/archive/";
$class="linked-day"; 
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{ 
$days = print_r(array($row['gl_date']=>array($link,$class)));
}

 

any ideas?

 

 

you're overwriting the array each time through your loop so it's only giving you the last one.

try this

$link="/weblog/archive/";
$class="linked-day"; 
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{ 
$days[$row['gl_date']] = array($link,$class)));
}

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.