Posted By

Wardy on 12/12/08


Tagged

mysql php enum set values


Versions (?)

Retrieve valid entries for a MySQL ENUM/SET column


 / Published in: PHP
 

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

  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. }

Report this snippet  

You need to login to post a comment.