View Full Version : how would I loop this?

08-10-2008, 06:58 AM
I have a PHP file that contains HTML and PHP code. I would like to separate the business logic and presentation logic using PHP savant template engine.
Okay, so in the PHP file i have echoed a variable ($thumbnail_image) by using print_r($thumbnail_image);
It prints out


Now I would like to take pictures/OP_2.png and pictures/OP_1.png and place them in an <img> so that it displays on the website. I just don't know how to create the loop in the template file so that they can display on the website. I'm not sure if I would use a foreach or a while loop to do this. PHP Savant supports both.

If it helps any, my PHP file looks something like this: (I took some parts of the whole file out)

$result = $db->query("SELECT * FROM oekakidta {$sql_where} {$sql_limit}");
$rownum = mysql_num_rows ($result);
for ($current_post = 0; $current_post < $rownum; $current_post++) {
$outerrow = mysql_fetch_array($result);
$row[] = $outerrow;
$tpl->assign('row', $row); // Assign the sql results to the template
// Master image calculation code goes here
$thumbnail_image = $master_image;
$tpl->assign('thumbnail_image', $thumbnail_image); // Assign $thumbnail_image to the template

My template file so far:

<div id="contentmain">
<?php foreach ($this->row as $outerrow): ?>
<!-- some code is here -->
<img src="<?php echo $this->thumbnail_image ?>" alt="Pic #<?php echo $outerrow['PIC_ID'] ?>" title="Pic #<?php echo $outerrow['PIC_ID'] ?>" /></a><br />
<!-- more code -->
<?php endforeach; ?>

So between <div id="contentmain"></div> should be pictures/OP_1.png and in another set below that should be pictures/OP_2.png. I'm just unsure how to do that.