[SMARTY] Nested Queries
Gary Smith <[email protected]>
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Message-ID | <BF1E746F.557E4%[email protected]> |
Aloha All,
I have a database that has two tables CUSTOMERS and RESERVATIONS. A
customer can have multiple reservations. I would like to display the
customers name and the types of reservations they made. Without templates I
would embed a second query within the results of the first query to find all
reservations with the current customerID. I can¹t figure out how to do this
with templates.
I have a file setup as such:
index.html
$query=
<<<SQL
SELECT *
FROM CUSTOMERS
INNER JOIN RESERVATIONS
ON CUSTOMERS.customerID = RESERVATIONS.customerID
ORDER BY CUSTOMERS.customerLastName ASC, CUSTOMERS.customerFirstName ASC
SQL;
$data = $DB->GetAssoc($query);
$tpl->assign('data', $data);
In my template I have :
index.tpl
{foreach from=$data item="entry"}
<tr align="left" valign="middle" bgcolor="{cycle
values='#dedede,#eeeeee'}">
<td>{$entry.customerFirstName|cat:"
"|cat:$entry.customerLastName}</td>
<td>{$entry.reservationType}</td>
</tr>
{foreachelse}
<tr align="left" valign="middle">
<td colspan="2">No records</td>
</tr>
{/foreach}
Thanks,
Gary