Re: [Phplib-users] Select Box!
Brought to you by:
nhruby,
richardarcher
From: Dark <dar...@gm...> - 2005-04-29 18:13:18
|
Why don=B4t you try to use parameters in the function as needed an call the= =20 function as many times as you need passing the apropiate values as=20 parameters? 2005/4/29, Marylly Araujo Silva <ima...@ya...>: >=20 > Like you answered me, I can use the function make_select_list() to make > select box. But how can I make more than one select box if i can't > declare the function more than once? >=20 > I'm wanting to do a pge using the PHPLIB Templates with two select boxes > ,beind one of them depends on the other to generate the option list and > after select the two select boxes will show a list from the database. >=20 > if you didn't understand i can give more details >=20 > please, help me >=20 > thanks any way >=20 > marylly > **Mya** >=20 > Andrew Crawford wrote: >=20 > > Hi Mya, > > > > Are you using PHPLIB's database abstraction? Are you using PHPLIB > > templates? > > > > If the answer to these questions is no, you have a general PHP > > question and should look for another mailing list or forum to get the > > answer. > > > > If the answer to both questions is yes, you should be able to do > > something like this: > > > > function make_select_list($selected) { > > $exampledb =3D new DB_Example; > > $query =3D "SELECT label,value FROM table ORDER BY label"; > > $exampledb->query($query); > > > > // Did we get any results? If not, fail appropriately ... > > > > // Loop template > > $loop_t =3D new Template_Example; > > > > // our mini-template > > $loop_t->set_var("option", "<option > > value=3D\"{value}\"{selected}>{label}</option>\n"); > > > > // put our data into the template > > while ($exampledb->next_record()) { > > $loop_t->set_var(array( > > "label" =3D> $exampledb->f("label"), > > "value" =3D> $exampledb->f("value"), > > "selected" =3D> ((!is_null($selected) and > > ($exampledb->f("value") =3D=3D $selected)) ? " selected" : ""))); > > $loop_t->parse("options", "option", true); > > } > > > > // return the options list > > return $loop_t->get_var("options"); > > } > > > > The returned value will then contain a series of options: > > > > <option value=3D"value1">Label 1</option> > > <option value=3D"value2">Label 2</option> > > ... > > <option value=3D"valuen">Label n</option> > > > > ... and you can put it into your main page template, assigning it to a > > template variable just like anything else. > > > > Template: > > > > <!-- top part of page goes here --> > > <select name=3D"example_select"> > > {option_list} > > </select> > > <!-- bottom part of page goes here --> > > > > > > Code: > > > > // Set selected to appropriate value > > $selected =3D ""; > > > > // Set up your template > > $t =3D new Template; > > $t->set_file('content', 'example_template.ihtml'); > > > > // Generate the option list > > $our_option_list =3D make_select_list($selected); > > > > // Fill in the variables > > $t->set_var('option_list', $our_option_list); > > > > // Output the page > > $t->parse('out', 'content'); > > $t->p('out'); > > > > I hope that helps. > > > > Andrew Crawford > > > > Marylly Araujo Silva wrote: > > > >> hello guys > >> > >> Can I create a select box and create the options using a db query > >> from the database? > >> > >> thanks > >> > >> Marylly > >> **Mya** > > > > >=20 > ------------------------------------------------------- > This SF.Net <http://SF.Net> email is sponsored by: NEC IT Guy Games. > Get your fingers limbered up and give it your best shot. 4 great events, = 4 > opportunities to win big! Highest score wins.NEC IT Guy Games. Play to > win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=3D20 > _______________________________________________ > Phplib-users mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phplib-users >=20 --=20 ________________________________ Los sabios tienen las mismas ventajas=20 sobre los ignorantes que los=20 vivos sobre los muertos. Arist=F3teles |