Retrieve valid entries for a MySQL ENUM/SET column


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



Copy this code and paste it in your HTML
  1. // grab possible SET/ENUM values and return an array
  2. function getPossibleValues($table,$field){
  3. $query = "SHOW COLUMNS FROM `$table` LIKE '$field'";
  4. $result = mysql_query($query);
  5.  
  6. if(mysql_num_rows($result)>0)
  7. {
  8. list(,$fields) = mysql_fetch_row($result);
  9. $options = explode("','",preg_replace("/(enum|set)('(.+?)')/","\2",$fields));
  10. return $options;
  11. }
  12. else
  13. {
  14. return array();
  15. return false;
  16. }
  17. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.