impulse a écrit :
Perso j'utilise cette methode pour creer mes select =>
Code :
- function createSelect($cnx, $tableName, $selectName, $selectClass, $selectValue, $selectOption, $defaultValue) {
-
- // create query to find distinct values of $selectValue in $tableName
- $query = "SELECT DISTINCT $selectValue, $selectOption FROM $tableName";
-
- // run the query on the DB
- $result = @ mysql_query ($query, $cnx);
- // retrieve all distinct values
- while ($row = @ mysql_fetch_array($result)) $resultBuffer[$row[$selectValue]] = $row[$selectOption];
- // start the select widget
- echo "\n<select class=\"$selectClass\" name=\"$selectName\">";
-
- // check for a default value
- if (isset($defaultValue))
- {
- // yes, there's a default value specified
- // check if the defaultValue is in the database values
- foreach ($resultBuffer as $value => $option)
- if ($option == $defaultValue)
- // yes, show as selected
- echo "\n\t<option value=\"$value\" selected>$option</option>";
- else
- // no, just show as an option
- echo "\n\t<option value=\"$value\">$option</option>";
- }
- else
- {
- // no defaultValue
- // show database values as options
- foreach ($resultBuffer as $value => $option)
- echo "\n\t<option value=\"$value\">$option</option>";
- }
-
- echo "\n</select>";
-
- }
|
Ceci dit, la rapidité d'execution n'est pas vraiment ma principale preoccupation.
|