Jump to content

Archived

This topic is now archived and is closed to further replies.

ayaycaptainchris

Array Problem

Recommended Posts

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:
[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'),
);
[/code]

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
[code]
$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'),
);
[/code]
it's not working. can someone please help me.

basically, it should end up like
[code]
$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'),
);

[/code]

Share this post


Link to post
Share on other sites
This should do the job:

[code]$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);

}[/code]

Share this post


Link to post
Share on other sites

×

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.