xoops forums

xsell

Quite a regular
Posted on: 2010/2/11 7:13
xsell
xsell (Show more)
Quite a regular
Posts: 245
Since: 2008/9/2 1
#1

XoopsFormSelect Array with db query

HI

How to fill XoopsFormSelect with data directly from the db.

I need to get the Category Name in Drop Down Select Option ..

This wht i tried .. but it Only Brings One Category Name ..

$sql "SELECT cat_id,cat_name FROM ".$xoopsDB->prefix("test_category");
$result $xoopsDB->query($sql);

while (list(
$cat_id$cat_name) = $xoopsDB->fetchRow($result) ) {
$select_element = new XoopsFormSelect('''cat');
     
$select_element->addOption($cat_id$cat_name);

}
          
$form->addElement($select_element);

ghia

Community Support Member
Posted on: 2010/2/11 8:02
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#2

Re: XoopsFormSelect Array with db query

Try with:
$select_element = new XoopsFormSelect('''cat');
while (list(
$cat_id$cat_name) = $xoopsDB->fetchRow($result) ) {
     
$select_element->addOption($cat_id$cat_name);
}
In your code the select_element gets every time recreated in the loop.

xsell

Quite a regular
Posted on: 2010/2/11 8:46
xsell
xsell (Show more)
Quite a regular
Posts: 245
Since: 2008/9/2 1
#3

Re: XoopsFormSelect Array with db query

Thx Ghia ... .. I dont know how i couldt See that .. :)