|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
tdm Smarty Rookie
Joined: 01 May 2003 Posts: 18
|
Posted: Mon May 05, 2003 6:59 pm Post subject: Array in Array, how to loop it in the array? |
|
|
I got the following array (Output of Debug Console):
Code: |
{$results} Array (1)
0 => Array (13)
uid => 1
user_email => robert10@chello.nl
user_passwd => patrick
user_firstname => Patrick
user_lastname => van Dissel
user_sex => M
user_birthdate => 1984-06-11
user_from => Lelystad
user_intrest => PC's
user_url => www.internetscala.nl
sn_regdate => 1988-06-11
0 => Array (2)
sidname => Dolfijnen
member => Y
1 => Array (2)
sidname => Scouts (PL)
member => Y |
A stripped down version of my template has looks like:
Code: |
{section name='uid'}
....
<html>
..{$results[uid].user_firstname} <!- show data
.......
{section name='userhistory'}
{$results[userhistory].sidname}
{/section}
{/section}
|
How can I create a loop which loops through the second part of the $results array?
Code: |
0 => Array (2)
sidname => Dolfijnen
member => Y
1 => Array (2)
sidname => Scouts (PL)
member => Y |
It's not that fancy, but the array always contains the user info of 1 (one) user, and then a bunch of groups where they are of have been a member of. How can I get this work?
(So it's a profile page)
Thanks[/code] |
|
Back to top |
|
tdm Smarty Rookie
Joined: 01 May 2003 Posts: 18
|
Posted: Mon May 05, 2003 8:41 pm Post subject: |
|
|
Oke, I got it working now.
I think there's a better way, but I can't find it.
Tips are welcome
The now PHP code looks like this:
Code: | $UserSql = 'SELECT * FROM asc_users WHERE asc_users.uid = '.$uid;
$UserResults = $db->query($UserSql);
$tmpUser = array();
$i = 0;
while ($mainrow = $UserResults->fetchRow(DB_FETCHMODE_ASSOC)) {
$tmpUser = array (
'uid' => $mainrow['uid'],
'user_email' => $mainrow['user_email'],
'user_passwd' => $mainrow['user_passwd'],
'user_firstname' => $mainrow['user_firstname'],
'user_lastname' => $mainrow['user_lastname'],
'user_sex' => $mainrow['user_sex'],
'user_birthdate' => $mainrow['user_birthdate'],
'user_from' => $mainrow['user_from'],
'user_intrest' => $mainrow['user_intrest'],
'user_url' => $mainrow['user_url'],
'sn_regdate' => $mainrow['sn_regdate']
);
$UserData[$i] = $tmpUser;
//Get UserHistory data from DB
$HistorySql = 'SELECT asc_sn_speltakken.sn_speltakname AS sidname,
asc_sn_userhistory.member
FROM asc_sn_speltakken,
asc_sn_userhistory
WHERE asc_sn_userhistory.user_id = '.$UserData[$i]['uid'].'
AND asc_sn_speltakken.sn_id = asc_sn_userhistory.sn_sid';
$HistoryResults = $db->query($HistorySql);
$tmpHistory = array();
$j = 0;
while ($subrow = $HistoryResults->fetchRow(DB_FETCHMODE_ASSOC)) {
$tmpHistory = array (
'sidname' => $subrow['sidname'],
'member' => $subrow['member']
);
$HistoryData[$j] = $tmpHistory;
$j++;
}
}
$tmpl->assign('UserData', $UserData);
$tmpl->assign('UserHistory', $HistoryData); |
And the loop section of my template:
Code: | {if $UserHistory}
<table width="100%" border="0" cellpadding="0" cellspacing="0">
{section name=history loop=$UserHistory}
<tr>
<td style="vertical-align: top; padding: 2px; border-bottom: 1px solid #00CC00;">
- {$UserHistory[history].sidname}&
{if $UserHistory[history].member == "Y"}
[<font color="#FFFF00"><strong>lid</strong></font>]
{/if}
</td>
</tr>
{/section}
</table>
{/if} |
It works but again, Tips are welcome |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|