Return to Snippet

Revision: 10202
at January 19, 2010 04:39 by ginoplusio


Updated Code
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 ;
}

Revision: 10201
at December 12, 2008 09:29 by ginoplusio


Updated Code
function set_and_enum_values( $table , $field ){
		$query = "SHOW COLUMNS FROM `$table` LIKE '$field'";
		$result = mysql_query( $query ) or die( 'error getting enum field ' . mysql_error() );
		$row = mysql_fetch_array($result);
		$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[$ar[$i]]=$ar[$i];
		return $arOut ;
}

Revision: 10200
at December 12, 2008 09:28 by ginoplusio


Initial Code
function set_enum_select( $table , $field ){
		$query = "SHOW COLUMNS FROM `$table` LIKE '$field'";
		$result = mysql_query( $query ) or die( 'error getting enum field ' . mysql_error() );
		$row = mysql_fetch_array($result);
		$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[$ar[$i]]=$ar[$i];
		return $arOut ;
}

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

Initial Description

                                

Initial Title
mysql php get enum values

Initial Tags
mysql, php

Initial Language
SQL