Individual Array Entries

Individual Array Entries

am 13.07.2007 00:53:27 von Larentium

Hi Everyone,

RE: Individual Array Entries

I am using a mini calendar script which uses the following array to enter
event dates.

$days = array(
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")
);
// 3, 8 & 22 = the day
// weblog/archive... = the link
// linked-day = the CSS class.

Because I get the event data from a database and loop through the results of
a query, I need to be able to insert each entry individually instead of as a
group.

The following code fails in that it only lists the last entry:

$days = array($theday[$y]=>array("#$thelink[$y]","linked-day"));

Using a concatenation fails altogether:

$days.= array($theday[$y]=>array("#$thelink[$y]","linked-day"));

I just do not know the proper syntax to individually insert entries into
this multidimensional array... Please help. Thank you.


Keith

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Individual Array Entries

am 13.07.2007 02:04:42 von Larentium

> I am using a mini calendar script which uses the following array to enter
> event dates.
>
> $days = array(
> 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")
> );
> // 3, 8 & 22 = the day
> // weblog/archive... = the link
> // linked-day = the CSS class.
>
> Because I get the event data from a database and loop through the results
> of a query, I need to be able to insert each entry individually instead of
> as a group.
>
> The following code fails in that it only lists the last entry:
>
> $days = array($theday[$y]=>array("#$thelink[$y]","linked-day"));
>
> Using a concatenation fails altogether:
>
> $days.= array($theday[$y]=>array("#$thelink[$y]","linked-day"));
>
> I just do not know the proper syntax to individually insert entries into
> this multidimensional array... Please help. Thank you.


I tried:
$days[$theday] = array("$thelink","linked-day");

But it only displays the last event.

Keith

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Individual Array Entries

am 13.07.2007 14:13:53 von James Gadrow

Here's how you can fill a multi-dimensional array:

$days = array(); //Declare $days
to be an array
while ($row = mysql_fetch_assoc($result)) //set variable $row to be an
associative array containing a row of results from your mysql query
array_push($days, $row); //Inserts a new record
into $days and stores $row in it. This creates a multi-dimensional array

Or, if you want it associative:

$days = array();
while ($row = mysql_fetch_assoc($result))
$days['whatever here'] = $row;

Hope that helps!

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php