Log in

View Full Version : Loops in templates


aragorn_reborn
12-04-2006, 03:45 PM
I have to make a custom page which queries a database and gets say n rows.

I store the rows in an array.

Now, i have to display the contents of each row, one line for one row.

For this, i need to have a for loop in the template.

How do i do this?

I hope my question is clear.....

peterska2
12-04-2006, 03:51 PM
You can't have a loop. What you need is a second template just containing the code required for the row and then call that template in the first template.

aragorn_reborn
12-08-2006, 08:07 AM
How exactly?

Look at the following code


eval('print_output("' . fetch_template('template1') . '");');
$sql = $db->query_read("SELECT name FROM " . TABLE_PREFIX . "people");
while ($array = $db->fetch_array($sql))
{
$name = $array["0"];
eval('print_output("' . fetch_template('template_row') . '");');
}
eval('print_output("' . fetch_template('template2') . '");');


template 1 contains

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle] - Submit Executive Summary for Mentoring</title>
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat" colspan="2">Heading</td>
</tr>
<tr>
<td class="alt1">Name: *</td>
<td class="alt1"><select name="name">


template_row is

<option name="$name">$name</option>

template2 is


</select></td></tr></table>
$footer

This doesnt work

Do i have to use $template_row in template1 ?? Please help!
Stuck at this thing for the last 2 days

Spiffware
12-08-2006, 10:44 AM
he needs a foreach command i think.