Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Looping question

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
case23_69
Smarty Rookie


Joined: 15 Apr 2004
Posts: 26

PostPosted: Thu Apr 15, 2004 7:13 pm    Post subject: Looping question Reply with quote

Hello,
I am new to smarty but not php.
Here's my SQL that will populate this template:

Code:

SELECT id_part, c_warehouse, m_price, v_title, t_description, c_category
FROM $part_table INNER JOIN $cat_table
ON ($part_table.id_category = $cat_table.id_category)
ORDER BY i_order



Now there is a bunch of rows, and each have a c_category. I want to GROUP by these categories in my template:
----------------------------------------------
Category1
Item Quantity Vendor Part Warehouse Price
.... a bunch of Category 1 items
----------------------------------------------
Category2
Item Quantity Vendor Part Warehouse Price
.... a bunch of Category 2 items

So, I want the header to only print once for each category.




Here's what I want to do:

[php:1:89d557f671]<?php
{section name=parts_index loop=$parts}
<!-- IF A NEW CATEGORY -->
<tr>
<th colspan="5"><br>{$category}<br><br></th>
</tr>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Vendor Part</th>
<th>Warehouse</th>
<th>Price</th>
</tr>
<!-- END IF A NEW CATEGORY -->


<tr>
<td>
<b>{$partTitle|nl2br}</b><br>
{$partDescription|nl2br}
</td>
<td>

<select name="{$partSelectName}"
<option value="" selected></option>
{html_options options=$partOptions selected=$selectedPart}
</select>
</td>
<td>{$partId}</td>
<td>{$partWarehouse}</td>
<td>${partPrice}</td>
</tr>
{/section}
?>[/php:1:89d557f671]


How do I do the IF section I have in comments? Can you create and assign to variables within the smarty template?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP