Enum to Array / SQL to PHP


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

adapted from http://www.gotocode.com/art.asp?art_id=275&


Copy this code and paste it in your HTML
  1. function LoadTypeValues($table, $column)
  2. {
  3. global $db;
  4. // Create a SQL Query to get the Columns Type information,
  5. // Open a database connection, execute the query, and retrieve
  6. // the result.
  7.  
  8. $sql = "show columns from $table like '$column'";
  9.  
  10. // Get the Type information, Remove "xxx(" from the front
  11. // and ")" from the end. Split the comma delimited values
  12. // into an array.
  13. $requete = mysql_query($sql, $db);
  14. while($enum = mysql_fetch_array($requete)) {
  15. $enum = $db->f('Type');
  16. $off = strpos($enum,"(");
  17. $enum = substr($enum, $off+1, strlen($enum)-$off-2);
  18. $values = explode(",",$enum);
  19.  
  20. // For each value in the array, remove the leading and trailing
  21. // single quotes, convert two single quotes to one. Put the result
  22. // back in the array in the same form as CodeCharge needs.
  23.  
  24. for( $n = 0; $n < Count($values); $n++) {
  25. $val = substr( $values[$n], 1,strlen($values[$n])-2);
  26. $val = str_replace("''","'",$val);
  27. $values[$n] = array( $val, $val );
  28. }
  29. }
  30. // return the values array to the caller
  31. return $values;
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.