Hello all.
Basically, I'm trying to populate a comboBox with the results of a mySQL query, and using PHPLIB templates and parsing to do it- I want to separate the display from the logic as much as possible. So, I've got my template all set up as follows -
..snip from rest of page...
<select name="blah" class="text" id="select4">
<option>--Please Select--</option>
<!-- BEGIN radioBlock -->
<option>{RADIO_OPTIONS}</option>
<!-- END radioBlock -->
..rest of page code...
my php looks like this -
<?php
//populate the combos...
function popMenu($menu){
//name and connect to the database..
require("--requirePath--");
mysql_select_db($database_devTest, $devTest);
//populate the recordset...
$menuList = array();
$qry = "SELECT des FROM tblsimpques WHERE cat = '".$menu."';";
$qryRes = mysql_query($qry, $devTest) or die(mysql_error());
// $numRows = mysql_num_rows($qryRes);
while($line=mysql_fetch_assoc($qryRes)){
array_push($menuList, $line['des']);
}
return $menuList;
close($devTest);
}
?>
<?php
include_once("template.inc");
$TEMPLATE_DIR="templates";
$OUT_TEMPLATE="template_2.htm";
$t=new template($TEMPLATE_DIR);
//set up the template page and blocks, etc...
$t=new Template($TEMPLATE_DIR);
$t->set_file("page", $OUT_TEMPLATE);
//setting blocks now...
$t->set_block("page", "radioBlock", "radio");
//populate the combo box...
$rs=popMenu('radio');
foreach($rs as $key=>$var){
$t->set_var("RADIO_OPTIONS", $var);
$t->parse("radio", "radioBlock", true);
}
?>
This actually does populate the drop-downs as suspected, but it also throws an error on loading the page -
Notice: Undefined index: radio in c:\Inetpub\php\template.inc on line 210
This is really cheesing me off, as I'm sure it's something simple. I tried reading the "Templates, the PHPLIB way" article here on phpbuilder, as well as searching the various forums, but can't find the answer. Either that or I've found it and not recognized it yet.
My apologies if I've already posted this here - a search didn't come up with it, and I've asked the question in several locations to no avail.
Please let me know what I'm missing, or point me to an easily understandable explanation - I can pick things up pretty quickly, but I'd like a simple explanation the first time through.
Thanks!