mysql php get enum values


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. FUNCTION set_and_enum_values( $table , $field ){
  2. $query = "SHOW COLUMNS FROM `$table` LIKE '$field'";
  3. $result = mysql_query( $query ) OR die( 'Error getting Enum/Set field ' . mysql_error() );
  4. $row = mysql_fetch_array($result);
  5. IF(stripos(".".$row[1],"enum(") > 0) $row[1]=str_replace("enum('","",$row[1]);
  6. ELSE $row[1]=str_replace("set('","",$row[1]);
  7. $row[1]=str_replace("','","\n",$row[1]);
  8. $row[1]=str_replace("')","",$row[1]);
  9. $ar = split("\n",$row[1]);
  10. FOR ($i=0;$i<COUNT($ar);$i++) $arOut[str_replace("''","'",$ar[$i])]=str_replace("''","'",$ar[$i]);
  11. RETURN $arOut ;
  12. }

URL: http://www.barattalo.it/2010/01/19/php-to-get-enum-set-values-from-mysql-field/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.