Re: [phplib] How can I populate a select box from a db query? From: Mike Green (Mike.Green <email protected>)
Date: 11/15/00

Here are some snippets from one of my projects where I do what I believe
you want using the DB_Sql and form classes:

$db = new DB_Sql;

$query = "SELECT * FROM reference_table ORDER BY document_type, author,
title";

if($db->query($query)){
    if($action == 'Edit'){
        $list_of_sources = array();
    }else{
        $list_of_sources = array(array("label"=>"New listing",
"value"=>"0"));
    }
    $counter = 1;
    while ($db->next_record()){
        $label_item = stripslashes($db->f('document_type'))." --
".($db->f('author')?stripslashes($db->f('author')).($db->f('title')?":
":""):"").stripslashes($db->f('title'));
        $list_of_sources[$counter++] = array("label"=>$label_item,
"value"=>$db->f('reference_id'));
    }
}else{
    $list_of_sources = array(array("label"=>"None available",
"value"=>"0"));
}

$f = new form;

$f->add_element ( array("type"=>"select",
                                "name"=>"reference_id",
                                "options"=>$list_of_sources,
                                "size"=>"1",
                                "value"=>$reference_id));

$f->show_element('reference_id');

I have modified the above a wee bit to try to get rid of some extraneous
(to your question) and potentially confusing bits. But it is still not
the most simple way to do it. ;-)

Cheers!

Mike Green

"White, Bob" wrote:

> Hi All,
> How can I populate a select box from an oracle db query?
> Any help would be greatly appreciated.
> Bob White
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: phplib-unsubscribe <email protected>
> For additional commands, e-mail: phplib-help <email protected>

--
Mike Green
SaeSolved::
http://www.saesolved.com
http://www.everypeople.net
http://www.sitewidgets.com
http://www.widgetchuck.com

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>