/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
FUNCTION set_and_enum_values( $table , $field ){ $query = "SHOW COLUMNS FROM `$table` LIKE '$field'"; $result = mysql_query( $query ) OR die( 'Error getting Enum/Set field ' . mysql_error() ); $row = mysql_fetch_array($result); IF(stripos(".".$row[1],"enum(") > 0) $row[1]=str_replace("enum('","",$row[1]); ELSE $row[1]=str_replace("set('","",$row[1]); $row[1]=str_replace("','","\n",$row[1]); $row[1]=str_replace("')","",$row[1]); $ar = split("\n",$row[1]); FOR ($i=0;$i<COUNT($ar);$i++) $arOut[str_replace("''","'",$ar[$i])]=str_replace("''","'",$ar[$i]); RETURN $arOut ; }
URL: http://www.barattalo.it/2010/01/19/php-to-get-enum-set-values-from-mysql-field/