?

Log in

Sep. 22nd, 2008 @ 01:17 pm problem with arrays
Hello,

I wonder if someone here could help:

I'm working on a calendar that reads information from a database, the code I've borrowed uses an array to populate the calendar:

$days = array(

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

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

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

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

);

So logically I tried:

$select="SELECT * FROM calendar WHERE smonth='$month' ORDER BY sday";
$rows = mysql_query($select,$calendar);
while ($row = mysql_fetch_row($rows)) {
$day=$row[1];
$daysx.="$day=>array('link','linked-day'),";
}
$days=array($daysx);

Which should give a similar result, however something doesn't work. Does anyone have any idea what is going on.
About this Entry
astro 10th aug 2007
fyremoon:
From:aeisor
Date:October 22nd, 2009 12:57 pm (UTC)
(Permanent Link)
Rather than try to populate at the end, populate as you go along. Replace:

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

with

$days[$day][0]="link"; $days[$day][1]="linked-day";

I realise this is a reasonably old post and you've probably solved it. I've never tried creating an array how you have, but if it works at all I would imagine your final ',' is throwing up the error. Perhaps you could also try:

$days=array(substr($daysx,0,-1));

Which will remove the final ',' before throwing into the array.
From:aeisor
Date:October 22nd, 2009 01:00 pm (UTC)
(Permanent Link)
I completely skipped over the 2008 on that, REALLY old post. Nevermind me.