[phplib] Problem with recursion From: Mark Henderson (mark <email protected>)
Date: 07/04/00

Greetings:

I am fairly new to both php and phplib, and not a seasoned programmer . I
recently wrote a little php routine to split a comma separated list and
create a selection list from it. It works great as a stand alone php
script. I wanted to insert that functionality into a phplib template that
I already have working, but the problem is that the template only displays
the last element of the array in the selection list box. I figure it has
something to do with the way the phplib template recurses through before
final output. Any suggestions are greatly appreciated. See snippets below:

Below is a test snippet. The actual template script sets many variables
based on calls to my database, so it was easier to just leave that in for
now. Using the sample code below, I only get the last element of my array
(red) to show in the list box. I don't get orange or purple to show in the
list. Below this snippet is a sample of the ihtml file that displays this
template.

--------------

<?php

    <email protected>("myhost", "mydb", "mypass");

    <email protected>("mydb");

   $result = mysql_query("SELECT * FROM products");

      $t = new Template( "/my/path/www/");

      $t->set_file( "MyFileHandle", "MyTemplate_color.ihtml");

          while ($myrow =  <email protected>($result)) {

              $color="orange,purple,red";
              $colorapart="\,";
              $now=split($colorapart, $color);

                 for ($index = 0; $index < count($now); $index++)

                    $testit = "<option
value=\"$now[$index]\">$now[$index]</option><p>\n";

                    $t->set_var("colorme", $testit);

                    $t->parse( "MyOutput", "MyFileHandle");

                    $t->p("MyOutput");
         }
?>

---------------------

MyTemplate_color.ihtml snippet

<html>
<body>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td width="33%">
<form method=post action="path to my Perl script">
     <div align="right"><font face="Arial, Helvetica, sans-serif"
size="2">${cost}</font><br>

<select name="select">
{colorme}
</select>

Thanks,

Mark