Multiple selectbox question

From: Date: Mon, 13 Nov 2000 17:48:34 +0000
Subject: Multiple selectbox question
Groups: php.general 
Request: Send a blank email to php-general+get-24998@lists.php.net to get a copy of this message
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>

« previous php.general (#24998) next »