Re: Enum MySQL and PHP

From: Date: Thu, 03 Aug 2000 03:17:43 +0000
Subject: Re: Enum MySQL and PHP
Groups: php.general 
Request: Send a blank email to php-general+get-9867@lists.php.net to get a copy of this message
there might be a better way, but this seems to work. function enum_to_option($table, $field) { $result = mysql_query("describe $table $field"); $row = mysql_fetch_array($result); #this gets something like enum('yes', 'no') $enum_values = $row["Type"]; #removes starting 'enum(' and the closing ')' $enum_values = substr ($enum_values, 5, -1); #removes all the single quotes from the string $enum_values = str_replace("'", "", $enum_values); $enum_values = explode (",", $enum_values); foreach($enum_values as $value) { echo "<option value=$value>$value</option>"; } } echo "<select>"; enum_to_option("table_name", "column_name"); echo "</select>"; hope this helps, -j -----Original Message----- From: Derick Schuetz <dschuetz@ausam.com> To: Php General List <php-general@lists.php.net> Date: Wednesday, August 02, 2000 1:27 PM Subject: [PHP] Enum MySQL and PHP >I have an Enum field in a MySQL database. How can I populate an HTML >dropdown list box with the Values for the Enum field? > >Derick Schuetz >dschuetz@ausam.com > > > >-- >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 >

« previous php.general (#9867) next »