Php Need help with array possibly multi dimensional

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ashton321
Forum Newbie
Posts: 3
Joined: Mon Oct 26, 2009 7:23 pm

Php Need help with array possibly multi dimensional

Post 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>';
?>
Last edited by califdon on Mon Oct 26, 2009 7:40 pm, edited 1 time in total.
Reason: Replaced code=text with code=php to highlight syntax.
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Re: Php Need help with array possibly multi dimensional

Post 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...
Post Reply