Return to Snippet

Revision: 10199
at December 12, 2008 06:50 by Wardy


Initial Code
// grab possible SET/ENUM values and return an array
function getPossibleValues($table,$field){
	$query = "SHOW COLUMNS FROM `$table` LIKE '$field'";
	$result = mysql_query($query);

	if(mysql_num_rows($result)>0)
	{
		list(,$fields) = mysql_fetch_row($result);
		$options = explode("','",preg_replace("/(enum|set)('(.+?)')/","\2",$fields));
		return $options;
	}
	else
	{
		return array();
		return false;
	}
}

Initial URL
http://www.jellyandcustard.com/2005/11/23/retrieve-valid-entries-for-a-mysql-enumset-column/

Initial Description

                                

Initial Title
Retrieve valid entries for a MySQL ENUM/SET column

Initial Tags
mysql, php

Initial Language
PHP