Re: [SMARTY] {section} with array that doesnt start with index 0

From: Date: Mon, 19 Aug 2002 14:05:06 +0000
Subject: Re: [SMARTY] {section} with array that doesnt start with index 0
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5760@lists.php.net to get a copy of this message
> From: "Peter Billen" <peter@clueless.be> > To: "'Smarty General'" <smarty-general@lists.php.net> > Date: Mon, 19 Aug 2002 13:15:17 +0200 > Subject: RE: [SMARTY] {section} with array that doesnt start with index 0 > > 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? no, you're perfectly right. i never said the array must be 0-based, non-associative during it's whole lifetime. just pull it through array_values() right before you pass it to Smarty::assign() -- FreeBSD 4.6-STABLE 4:03PM up 10 days, 3:58, 21 users, load averages: 0.01, 0.03, 0.00

« previous php.smarty.general (#5760) next »