RE: [SMARTY] {section} with array that doesnt start with index 0
| From: | Peter Billen | Date: | Mon, 19 Aug 2002 11:15:17 +0000 |
| Subject: | RE: [SMARTY] {section} with array that doesnt start with index 0 | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5758@lists.php.net to get a copy of this message | ||
I found another problem with not using primary keys as indices.
Imagine you have 2 queries, 1 query to get the 'games' and another query
to get the 'leagues' from the database. In each game, they play an
undefined number of leagues. So a league is a sub-structure of a game.
In the first query, you fill in the games into the array. Fe:
$array[0]['game'] = "quake 1";
$array[0]['game_id'] = 1;
$array[1]['game'] = "quake 2";
$array[1]['game_id'] = 2;
...
In the second query, you have to fill in the leagues. However, you don't
know WHERE to fill it in, because you f.e. don't know where the game
"quake 1" is located (index 0? index 4? index ..?)
So the Y in $array[Y]['leagues']['league_name'] = "Quake 1 International
Bla Bla League"; is unknown?
If you had use primary keys as indices, you could have easily done:
$array[$row['game_id']]['leagues'][$row['league_id']]['league_name']
=
"Quake 1 International Bla Bla League";
Or am I wrong?
Peter
-----Original Message-----
From: Roman Neuhauser [mailto:neuhauser@bellavista.cz]
Sent: maandag 19 augustus 2002 12:34
To: 'Smarty General'
Subject: Re: [SMARTY] {section} with array that doesnt start with index
0
> From: "Peter Billen" <peter@clueless.be>
> To: "'Smarty General'" <smarty-general@lists.php.net>
> Date: Mon, 19 Aug 2002 12:19:17 +0200
> Subject: RE: [SMARTY] {section} with array that doesnt start with
index 0
> But what is then the best option to construct the array:
>
> $array[0]['countryName'] = "Belgium";
> $array[0]['countryNameShort'] = "BE";
>
> $array[1]['countryName'] = "United Kingdom";
> $array[1]['countryNameShort'] = "UK";
>
> or
>
> $array['countryNames'][0] = "Belgium";
> $array['countryNamesShort'][0] = "BE";
>
> $array['countryNames'][1] = "United Kingdom";
> $array['countryNamesShort'][1] = "UK";
this basically depends on your taste, but i find the first version
more logical.
> I myself suppose the best one is the first one, because it's easier
(is
> it?) to loop through. However with option 1, I guess you can't use the
> array_push function.
array_push($foo, array('name'=>'Belgium',
'code'=>'BE'));
but this doesn't belong to this list.
--
FreeBSD 4.6-STABLE
12:28PM up 10 days, 23 mins, 17 users, load averages: 0.00, 0.19, 0.25
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php