note 22457 added to function.mysql-fetch-field

From: Date: Wed, 19 Jun 2002 00:56:38 +0000
Subject: note 22457 added to function.mysql-fetch-field
Groups: php.notes 
Request: Send a blank email to php-notes+get-31995@lists.php.net to get a copy of this message
#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. -- http://www.php.net/manual/en/function.mysql-fetch-field.php http://master.php.net/manage/user-notes.php?action=edit+22457 http://master.php.net/manage/user-notes.php?action=delete+22457 http://master.php.net/manage/user-notes.php?action=reject+22457

« previous php.notes (#31995) next »