note 22457 deleted from function.mysql-fetch-field by danbrown

From: Date: Sat, 20 Jun 2009 02:17:23 +0000
Subject: note 22457 deleted from function.mysql-fetch-field by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157162@lists.php.net to get a copy of this message
Note Submitter: kflam at awc dot net dot au ---- #Input: the table name and the enum field #Output: an array that stores all options of the enum field or #false if the input field is not an enum function getEnumOptions($table, $field) { $finalResult = array(); if (strlen(trim($table)) < 1) return false; $query = "show columns from $table"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ if ($field != $row["Field"]) continue; //check if enum type if (ereg('enum.(.*).', $row['Type'], $match)) { $opts = explode(',', $match[1]); foreach ($opts as $item) $finalResult[] = substr($item, 1, strlen($item)-2); } else return false; } return $finalResult; } The function could be handy when making a selection option without typing all the options items respectively.

« previous php.notes (#157162) next »