Re: Multiple selectbox question

From: Date: Mon, 13 Nov 2000 17:53:26 +0000
Subject: Re: Multiple selectbox question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-25000@lists.php.net to get a copy of this message
Sure - this is the easiest way: <? $selected = array(); $sql = "SELECT * FROM select_box_table"; $r = mysql_query($sql); while($row = mysql_fetch_array($r)){ $selected[] = $row['id']; } $sql = "SELECT * FROM full_select_box_table"; $r = mysql_query($sql); while($row = mysql_fetch_array($r)){ echo '<OPTION VALUE="'.$row['id'].'" '; if(in_array($row['id'],$selected)){ echo ' SELECTED '; } echo '>'.$row['title'].'</OPTION>'."\n"; } ?> On Mon, Nov 13, 2000 at 06:48:34PM +0100, gerry wrote: > Hi, > > I'm trying to find a sollution for a multiple selectbox > > I have no problems using the count function to save the multiple selections > to the database, BUT i want to load them again (and be preselected) so that > people can edit them > > Somebody will probably have done this before, i just hope that somebody want > to share an example script with me. > > The script i have included does select the items that where saved but prints > the list more then once in the selecbox... > > Thanks, > Gerry > > $img_id = 68; > > $sql = "SELECT * FROM download_keyw_img WHERE image_id = $img_id"; > $sql_result = mysql_query($sql); > while ($row = mysql_fetch_array($sql_result)) { > $keywords[] = $row["keyword_id"]; > } > ?> > <select name="keywords[]" size="7" multiple> > <? > $sql = "SELECT * FROM download_keywords"; > $sql_result = mysql_query($sql); > $count=count($keywords); > > while ($row = mysql_fetch_array($sql_result)) { > $keyw_id = $row["id"]; > $keyword = $row["naam"]; > > for ($i = 0; $i < $count; ++$i) { > > if ($keyw_id == $keywords[$i]) { > $checked = "selected"; > } else { > $checked = " "; > } > > echo("<option value=\"$keyw_id\" > $checked>$keyword</option>"); > } > } > ?> > </select> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ================================================================================ = Joe Stump joestump98@yahoo.com http://www.miester.org = ================================================================================ "Real programmers don't comment their code. It was hard to write, it should be hard to understand."

« previous php.general (#25000) next »