Jump to content

Dynamically create an array - help


byroncoolie

Recommended Posts

Friends,

 

I have a PHP script that populates a calendar based on an array as follows:

 

$days = array(2=>array('javascript:showWhatsOnText(2);','linked-day'),

3=>array('javascript:showWhatsOnText(3);','linked-day'),

4=>array('javascript:showWhatsOnText(4);','linked-day'));

echo generate_calendar(2011, 4, $days, 1, '#');

 

where, for instance, the 2, 3 4 are the days of the month,

 

By extracting a series values from a MySQL database how would I generate this array dynamically.

E.g I have startday, startmonth, name and text fields in the database and would need to loop through them all to create the array.

 

I tried playing around with something like this without any luck:

 

$queryCat1 = "SELECT * FROM $dbCalendarEvents ORDER BY id ASC"; // WHERE visible = '1'

$result1 = mysql_query($queryCat1) or die (mysql_error());

$num1 = mysql_num_rows($result1);

$i=0;

$daysArray = array();

while ($i < $num1) {

$startday=mysql_result($result1,$i,"startday");

$startmonth=mysql_result($result1,$i,"startmonth");

$name=mysql_result($result1,$i,"name");

$name=mysql_result($result1,$i,"name");

$copy=mysql_result($result1,$i,"copy");

 

$daysArray[$i] = $startday=>array('/weblog/archive/2004/Jan/02','linked-day');

 

$i++;

}

 

Your help is appreciated.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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