Jump to content

the select menu to get an ENUM mySql field repeats the values ten times


odisseo83

Recommended Posts

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>";

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.