Forum Moderators: coopster
So, I start with this:
// $column_definition = $db->query_to_array("SHOW COLUMNS FROM `sp_sizes` LIKE 'category'");
// the line above is how I am actually getting the print_r'd data below, but it won't work without the DB class I use and with an appropriately setup table definition, so here's a handy line to build the relevant part of the array:
$column_definition = array( array("Type"=>"enum('Standard','Discount','Expedited')") );
print_r($column_definition);
/*
[0] => Array
(
[Field] => shiptype
[Type] => enum('Standard','Discount','Expedited')
[Null] => YES
[Key] =>
[Default] =>
[Extra] =>
)
*/
So, I think I turn that Type = enum thing into an array with this:
$shiptype = str_replace( "enum(", '$shiptype_possible_categories = array(', $column_definition[0]['Type']).';';
echo $shiptype;
// $shiptype_possible_categories = array('Standard','Discount','Expedited');
eval($shiptype);
print_r($shiptype_possible_categories);
/*
Array
(
[0] => Standard
[1] => Discount
[2] => Expedited
)
*/
But since this involves using eval, I was hoping someone else could take a look at it. And perhaps someone has a more elegant way of getting the possible enum values out of a mysql table?
Working on the weekend, no wonder I'm having trouble concentrating... :(
preg_match_all("/'([^\']*)'/", $column_definition[0]['Type'], $matches);
$shiptype_possible_categories = $matches[1];
print_r($shiptype_possible_categories);