Revision: 4441
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 12, 2007 08:35 by clapfouine
Initial Code
function LoadTypeValues($table, $column) { global $db; // Create a SQL Query to get the Columns Type information, // Open a database connection, execute the query, and retrieve // the result. $sql = "show columns from $table like '$column'"; // Get the Type information, Remove "xxx(" from the front // and ")" from the end. Split the comma delimited values // into an array. $requete = mysql_query($sql, $db); while($enum = mysql_fetch_array($requete)) { $enum = $db->f('Type'); $off = strpos($enum,"("); $enum = substr($enum, $off+1, strlen($enum)-$off-2); $values = explode(",",$enum); // For each value in the array, remove the leading and trailing // single quotes, convert two single quotes to one. Put the result // back in the array in the same form as CodeCharge needs. for( $n = 0; $n < Count($values); $n++) { $val = substr( $values[$n], 1,strlen($values[$n])-2); $val = str_replace("''","'",$val); $values[$n] = array( $val, $val ); } } // return the values array to the caller return $values; }
Initial URL
Initial Description
adapted from http://www.gotocode.com/art.asp?art_id=275&
Initial Title
Enum to Array / SQL to PHP
Initial Tags
mysql, php, array
Initial Language
PHP