Hi
What i want to do is to have a HTML select that contains values read from my database?
i'm reading data for the values of a HTML Select.
i use the below code to get the values from my database. i echo these to the screen and they're as expected.
$sql="SELECT * FROM CallType;";
$rs=odbc_exec($conn,$sql);
for ($row=0;odbc_fetch_row($rs);$row++)
{
$CallType=odbc_result($rs,"CallType");
$one = array(
$row => $CallType
);
echo $one[$row];
}
then using the below HTML call buildSelect function(i obtained from the web), but this ownly puts the 1st and last values obtained from the database into the Select.
Can anyone explain how it works?
<select name="CallType">
<? buildSelect($one, array("Call In (Repairs)", "true", "")) ?>
</select>
function buildSelect($selArr, $selOpt){
$selectText = $selOpt[0];
if ($selectText != "") {
$selDefault = "selected";
if ($selOpt[1] == "true") {
$selDefault = "";
}
echo "<option $selDefault>$selectText</option>\n";
}
foreach($selArr as $key => $value){
$sel = "";
for ($loop = 2; $loop < count($selOpt); $loop++) {
if ($selOpt[$loop] == $key) {
$sel = "selected";
}
}
echo "<option $sel value='$key'>$value</option>\n";
}
return;
}