smartfaq
SmartFAQ is developed by The SmartFactory (http://www.smartfactory.ca), a division of InBox Solutions (http://www.inboxsolutions.net)

How do I populate a dropdown box from a xoops table?
Requested and Answered by Kaotik on 2005/9/19 17:53:56 (6802 reads)
Create a standard html form then add the following code:
<SELECT name="dropdown[]" size="10" multiple id="select">
<?php
$query 
$xoopsDB->query(' SELECT * FROM ' $xoopsDB->prefix('xoops_table'));
while (
$row $xoopsDB->fetchArray($query))
{
$sel $row['field1'];
$id =$row['field2'];
echo 
"<OPTION VALUE='$id'>$sel</OPTION>n";
}
?>
</SELECT>


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]."<br>";
//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">


The comments are owned by the author. We aren't responsible for their content.
  • Friend of XOOPS

 Interesting

Can you elaborate a lil more on this feature? What I have in mind is setting up an automotive type form.

Example

First tab would be

Name:
Address:
City:
State:
Country:
Phone:

Second tab would be
Year:
2006
2005
2004

Make:
Chev
Dodge
Ford

Model:
Caprice
Impala
Nova

Parts Needed:

Ect. Ect.

Third tab would be Shipping instructions or something...

Have a look here at this center block design.
http://www.bahut.com/
I would like to set up a form system the same way. Would it be hard to pass the data all the way to the end of the tabs then submit the form.

I would love to pull the cats from an XOOPS table.

I hope this makes sence...

 
  • Quite a regular

 Re: Interesting

Quote:


A Propos - Tous droits réservés à Bahut.com © 2005 - XOOPS Ghost Reloaded - Contact


http://www.bahut.com/
Xoops Ghost Reloaded

 
  • Friend of XOOPS

 Please fix this page

I think this page is broken? 2 of the code examples are not displaying correctly?

 
  • Module Developer

 Think the idea was to write this..

Create a standard html form then add the following code:

<SELECT name="dropdown[]" size="10" multiple id="select">
<?php

$query 
$xoopsDB->query(' SELECT * FROM ' $xoopsDB->prefix('xoops_table'));

while (
$row $xoopsDB->fetchArray($query))
{
$sel $row['field1'];
$id =$row['field2'];
echo 
"<OPTION VALUE='$id'>$sel</OPTION>n";
}
?>
</SELECT>


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]."<br>";
//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">