[prev in list] [next in list] [prev in thread] [next in thread] 

List:       smarty-general
Subject:    [SMARTY] Nested Queries
From:       206.126.9.133
Date:       2005-08-10 0:55:43
Message-ID: BF1E746F.557E4%gts () tsu ! biz
[Download RAW message or body]


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




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic