{section} question...
| From: | John William | Date: | Thu, 27 Feb 2003 09:39:27 +0000 |
| Subject: | {section} question... | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-8277@lists.php.net to get a copy of this message | ||
Hello everyone...
I really tired from getting a solution for my problem... its probably easy
to fix but I couldn't get a solution..
I looked at the manual millions times... Unfortuantely , no benfits from
reading :(
I tried here
http://smarty.php.net/manual/en/language.function.section.php
- Example
7-18. nested sections
but they are putting the template example, and don't type anything about PHP
code
Let's assume thats we are programming a really simple bulletin boards script
there are 2 mysql tables:
1- categories
| - cat_id (smallint 4)
| - cat_title (char 100)
2- boards
| - board_id
| - cat_id
| - board_title
let's assume that there are some recoreds in each table as described below:
categores (2 recoreds):
cat_id cat_title
1 computer
2 arts
boards (3 recoreds):
board_id cat_id board_title
1 1 security
2 1 hardware
3 2 all arts
I want to create an page contains list of categories and boards ..
the PHP code will be:
============================
// Define needed variables
$Category = array();
$Forum = array();
$i = 0; $z =0; // Counters (needed for indexing array elements)
// - |-------------------------------|
// - | C A T E G O R I E S |
// - |-------------------------------|
// Get categories
$results = $DB->query("Select cid, c_title From categories");
while ( list($cID,$cTitle) = mysql_fetch_array($results) ) {
// Reset variables (To clear variable contents which assigned in previous
loop)
$z = 0;
// Add element of categories array contains this category informations
$Category[$i] = array("ID" => $cID,
"Title" => $cTitle);
// Get category's forums..
$forumsresults = $eBoards->DB->query("Select * From boards Where cid =
'$cID' ");
// + |-------------------------------|
// + | B O A R D S
// + |-------------------------------|
// Start of Forums loop,
while ( $Forums = mysql_fetch_array($forumsresults) ) {
// Add element of forums array contains this forum informations
$Forum[$z] = array( "Title" => $Forums[f_title]);
// Increase Counter
$z++;
}
// End of Forums loop,
// Increase Counter
$i++;
// Assign informations which we got to template variables
$Smarty->assign("Category", $Category);
$Smarty->assign("forums", $Forum);
}
============================
The template file:
============================
<table>
{section name=cats loop=$Category}
<tr class='TableHeader' width='100%'><td width=1%>*
</td><td
width='28%'>{$Category[cats].Title}</a></td></tr>
{section name=forum loop=$forums[cats]}
<tr width='100%'><td width=1%> |-</td>
<td>{$forums[cats][forum].Title} </td>
</tr>
{/section}
{/section}
</table>
======================================
Thanks all,
Regards,