Jump to content


Photo

Array Problem


  • Please log in to reply
1 reply to this topic

#1 ayaycaptainchris

ayaycaptainchris
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 31 May 2006 - 06:27 AM

I am trying to modify a premade php calendar that i have found, but cant seem to make it work.
i have been trying for days to achieve this, but i have failed.

basically, the premade php calendar has the code:
$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'),
); 

I want to chagne it to something that accesses the database. I have a table called "calendar" in my database

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
DATE MONTH LINK EVENT
3 May [a href=\"http://www.3.com\" target=\"_blank\"]http://www.3.com[/a] Test
4 May [a href=\"http://www.4.com\" target=\"_blank\"]http://www.4.com[/a] Test 2
5 May [a href=\"http://www.5.com\" target=\"_blank\"]http://www.5.com[/a] Test 3
6 May [a href=\"http://www.6.com\" target=\"_blank\"]http://www.6.com[/a] Test 4
[/quote]

and i want it to transform to
$sql = mysql_query("SELECT date, month, link, event FROM calendar where month='May'");

$row = mysql_fetch_array($sql);

$date = $row['date'];
$month = $row['month'];
$link = $row['link'];
$event = $row['event'];


$days = array(
    $date=>array('$link', '$event'),
); 
it's not working. can someone please help me.

basically, it should end up like
$days = array(
    3=>array('http://www.3.com','Test'),
    4=>array('http://www.4.com','Test 2'),
    5=>array('http://www.5.com','Test 3'),
    6=>array('http://www.6.com','Test 4'),
); 



#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 31 May 2006 - 02:52 PM

This should do the job:

$sql = mysql_query("SELECT date, month, link, event FROM calendar WHERE month='May'");

while ($row = mysql_fetch_array($sql)) {

   $date = $row['date'];
   $month = $row['month'];
   $link = $row['link'];
   $event = $row['event'];

   $days[$date] = array($link, $event);

}

~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users