We Must Design Posted June 20, 2007 Share Posted June 20, 2007 I have created a combo/ select box that takes information from a database. I am wanting to duplicate this select box 5 times and insert the result back into a row. The data from the select boxes will be saved as 1|5|8|3|4 in the database. What will be the best method to duplicate the select box 5 times? Is it best to use a while loop or create an array? Thanks in advance, Chris Link to comment https://forums.phpfreaks.com/topic/56359-multiple-select-boxes/ Share on other sites More sharing options...
epic_era Posted June 20, 2007 Share Posted June 20, 2007 the best way to duplicate entries of this type is to create a class and then just make instances of it, kinda like this example that i have: "hope it helps" class test{ var $table; var $database; var $NAME2; var $ID1; var $tablefieldd; var $tablefieldv; function hihi(){ mysql_connect($host,$this->NAME2,$this->ID1); @mysql_select_db($this->database) or die( "Database not found"); $query = "SELECT * FROM $this->table"; $result1=mysql_query($query); $num2=mysql_num_rows($result1); $i=0; while ($i < $num2) { $data1=mysql_result($result1,$i,$this->tablefieldv); $data2=mysql_result($result1,$i,$this->tablefieldd); ?> <option value="<? echo $data1;?>"><? echo $data2;?> <?php $i++; } mysql_close(); }} and then call it with: //creating a new object of the class test $test2= new test; //here you must put the name of your database between "" $test2->database="fenologico"; //here you must put the name of the table from where the data will be taken instead of "fenologico " $test2->table="especie"; //the name of the BD user instead of "root" $test2->NAME2="root"; //the DB user id $test2->ID1=""; //here you must put the name of the field from the table that will be displayed instead of "ombrecomun" $test2->tablefieldd="nombrecomun"; //here you can put the value that each option will take $test2->tablefieldv="id"; //call the function that will create the list $test2->hihi(); sorry if it's not what you need Link to comment https://forums.phpfreaks.com/topic/56359-multiple-select-boxes/#findComment-278844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.