Page 1 of 1

Php Need help with array possibly multi dimensional

Posted: Mon Oct 26, 2009 7:26 pm
by ashton321
Hello
I am trying to highlight the days on my calendar based on the dates that i have in my database. Currently I can only get it to display the last element in the database which leads me to believe that i have an error in my arrays. The function accepts days in an array to be treated special. I can hard code the array but i want it to work with my database. Any help would be greatly apperciated Here is my code:

Code: Select all

  
<?php
             ## My database
             $query = mysql_query("SELECT * FROM speaking_engagements");
   while($result = mysql_fetch_array($query)){
   $dates = $result['date'];
   $dates = explode('-',$dates);
   $dates = $dates[2];
   }
 
   $time = time(); 
   $today = date('j',$time); 
   $days = array(
      $today=>array(NULL,NULL,'<span style="color: red; font-weight: bold; font-size: larger;">'.$today.'</span>'),
      $dates=>array('#'), 
        8=>array('#'),  ## a hard coded one that works
    );
   $today = getdate();
   $year = $today['year'];
   $month = $today['mon'];
   echo '<div id="calendar">';
    echo generate_calendar($year, $month, $days, 3, NULL, '/weblog/archive/2004/Jan'); 
   echo '</div>';
?>

Re: Php Need help with array possibly multi dimensional

Posted: Mon Oct 26, 2009 11:10 pm
by mischievous
Well looks like you continue to place your dates or days inside the same element in the array... thus the last element is only going to be in the variable.

simply add brackets in front of $days like $days[]

Code: Select all

 
$days = array();
$days[] = array(
   $today=>array(NULL,NULL,'<span style="color: red; font-weight: bold; font-size: larger;">'.$today.'</span>'),
   $dates=>array('#'),
   8=>array('#'),  ## a hard coded one that works
);
should result in:

$days[0] = array(
$today1=>array(NULL,NULL,'<span style="color: red; font-weight: bold; font-size: larger;">'.$today.'</span>'),
$dates1=>array('#'),
8=>array('#'), ## a hard coded one that works
);
$days[1] = array(
$today2=>array(NULL,NULL,'<span style="color: red; font-weight: bold; font-size: larger;">'.$today.'</span>'),
$dates2=>array('#'),
8=>array('#'), ## a hard coded one that works
);

etc etc...