odisseo83 Posted April 14, 2010 Share Posted April 14, 2010 Hi everybody, I have a table on a mySql DB with an Enum field. I used The function reported below to get the values of that field, but after I created the select it gives me in the drop down menu every value repeated twice and every list of double values repeated ten or more times. Moreover the browser cannot thorough load the page and after a while it crashes. Is it wrong what I did? What should I do? Thank to everybody who will give me suggestions function enum_select($table,$field) { $result=mysql_query("SHOW COLUMNS FROM `$table` LIKE '$field'"); if(mysql_num_rows($result)>0){ $row=mysql_fetch_row($result); $options=explode("','", preg_replace("/(enum|set)\('(.+?)'\)/","\\2", $row[1])); $options2 = array(); foreach ($options as $value) { $options2[] = array( 'value' => $value, 'display' => htmlentities($value) ); } echo "<br /><br />"; print_r($options2); #echo $options2; } else { $options=array(); } return $options2; } echo " <select name=\"scegli_tipo\"> "; while ($matrioshka_tipo = enum_select("opera","opera_tipo")){ foreach ($matrioshka_tipo as $array_interno) foreach ($array_interno as $valore) if (isset($_POST["scegli_tipo"]) && $_POST["scegli_tipo"] == $valore) echo "<option value='{$valore}' selected='selected'>{$valore}</option>"; else echo "<option value='{$valore}'>{$valore}</option>"; } echo "</select>"; Link to comment https://forums.phpfreaks.com/topic/198514-the-select-menu-to-get-an-enum-mysql-field-repeats-the-values-ten-times/ Share on other sites More sharing options...
ialsoagree Posted April 15, 2010 Share Posted April 15, 2010 I don't see how your while loop check can ever fail, you have no way of stopping the loop that I saw... while ($matrioshka_tipo = enum_select("opera","opera_tipo")){ // $matrioshka_tipo can always have enum_select assigned to, the loop never ends! Link to comment https://forums.phpfreaks.com/topic/198514-the-select-menu-to-get-an-enum-mysql-field-repeats-the-values-ten-times/#findComment-1042606 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.