Jump to content

[SOLVED] A coding solution required


fyremoon

Recommended Posts

I'm working with a calendar that uses an array of arrays to store events on a day to day basis, like this:

 

$days = array(

2=>array('link','linked-day'),

3=>array('link','linked-day'),

8=>array('link','linked-day'),

22=>array('link','linked-day'),

);

 

I would like to read these from a database, so I logically tried this:

$select="SELECT * FROM calendar WHERE month='$month' ORDER BY day";

$rows = mysql_query($select,$calendar);

while ($row = mysql_fetch_row($rows)) {

$day=$row[1];

$daysx.="$day=>array('link','linked-day'),";

}

$days=array($daysx);

 

I was hoping I would get the same result but although when I echo the value of $daysx, it looks similar I don't get a result.

 

Does anyone know how I can populate such an array using a database?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/125540-solved-a-coding-solution-required/
Share on other sites

I'll assume the col names are day, link, linked_day (as SELECT * tells us nothing)

 

$select="SELECT day, link, linked_day FROM calendar WHERE month='$month' ORDER BY day";
$rows = mysql_query($select,$calendar);

$days = array();
while (list ($day, $link, $linked_day) = mysql_fetch_row($rows)) {
    $days[$day]= array ($link, $linked_day);
}

Archived

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

×
×
  • 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.