How do I populate a dropdown box from a xoops table?

Requested and Answered by Kaotik on 2005/9/19 17:53:56

How do I populate a dropdown box from a xoops table?

Create a standard html form then add the following code:


$query $xoopsDB->query(' SELECT * FROM ' $xoopsDB->prefix('xoops_table'));
while (
$row $xoopsDB->fetchArray($query))
{
$sel $row['field1'];
$id =$row['field2'];
echo 
"$id'>$seln";
}
?>
This will create a var called $dropdown which is an array. To read through the results you can use this:
$count=count($dropdown);
for (
$i=0$i<$count$i++) {
echo 
"result: ".$dropdown[$i]."
"
;
//do something else with each selected option.
}
IN case you don't want the select box to be multiselect, replace this:
<SELECT name="dropdown[]" size="10" multiple id="select">
with this:
<SELECT name="dropdown" size="10" id="select">

This Q&A was found on XOOPS Web Application System : https://xoops.org/modules/smartfaq/faq.php?faqid=514