I have a unique problem that I cannot seem to find or figure out the answer to because I am trying to do a few things at once. I've tried researching each thing to find out the answer but it is unfortunately escaping me. :C
Essentially, I want to print an array inside of an array using assign_block_vars. Here is the HTML code that I would be using to display the SQL/PHP information -
* Active Players * (where active = 1 )
<!-- BEGIN activeplayers -->
<a href="{activeplayers.organizer}">{activeplayers.username}</a><br>
<!-- BEGIN charlist -->
- {charlist.charname}, {charlist.charrace}<br>
<!-- END charlist -->
<br><br>
* Inactive Players * (where active = 0 )
<!-- END activeplayers -->
<!-- BEGIN inactiveplayers -->
<a href="{inactiveplayers.organizer}">{inactiveplayers.username}</a><br>
<!-- BEGIN charlist -->
- {charlist.charname}, {charlist.charrace}<br>
<!-- END charlist -->
<br><br>
<!-- END inactiveplayers -->
The information is coming from two tables, like so:
table: roster_players
-------------------------------------------------
| username | organizer | active |
-------------------------------------------------
| Amy | http://www.google.com | 1 |
| John | http://www.msn.com | 0 |
| David | http://www.google.com | 1 |
| Jane | http://www.msn.com | 1 |
-------------------------------------------------
table: roster_characters
-------------------------------------------------
| player | charname | charrace |
-------------------------------------------------
| Amy | Apple | Elf |
| Amy | Turkey | Human |
| David | Cupholder | Elf |
| John | Blueberry | Human |
-------------------------------------------------
Where my problem is! This is the PHP/SQL I have tried working with and I am sure something is wrong with my foreach() statements, but I can't figure it out. I intended on running the code below twice, once for where p.active = 1 and again for p.active = 0, to make two separate lists.
$sql = 'SELECT p.active AS active, p.username AS username, p.organizer AS organizer, p.active AS active, c.player AS player, c.charname AS charname, c.charrace AS charrace
FROM `roster_characters` c
INNER JOIN `roster_players` as p
ON c.player = p.username
where p.active = 1';
$result = $db->sql_query($sql);
$playerlist = array();
$characterlist = array();
while ($row = $db->sql_fetchrow($result))
{
foreach ($playerlist as $player => $playerlist)
{ $template->assign_block_vars('activeplayers', array (
'USERNAME' => $player,
'ORGANIZER' => $row['organizer'],
));
foreach ($playerlist as $row['username'] => $row['charname'])
{
$template->assign_block_vars('players.charlist', array(
'CHARNAME' => $row['charname'],
'CHARRACE' => $row['charrace'],
));
}
}
}
The end result would look like this:
* Active Players * (where active = 1 )
Amy
- Apple, Elf
- Turkey, Human
David
- Cupholder, Elf
* Inactive Players * (where active = 0 )
John
- Blueberry, Human
Thank you for your time and help!!!