You can create an array with all ENUM options, but this is dangerous, because you have to make changes on multiple places (in the code and in the database), so it's better to fetch the ENUM options from the field and display them in a list to be selected.
To get information about a specific field in the DB, use this query:
SHOW COLUMNS FROM `table` LIKE 'column_name'
This returns an object containing a variable (Type) with the ENUM options. If you parse these you can get an array with all values. This function gets all values and returns them in an array:
public function getCategories() {
$query = "SHOW COLUMNS FROM `pages` LIKE 'category'";
$result = $this->dcd->fetchObject($query);
$result = str_replace(array("enum('", "')", "''"), array('', '', "'"), $result->Type);
$arr = explode("','", $result);
return $arr;
}
$query = "SHOW COLUMNS FROM `pages` LIKE 'category'";
$result = $this->dcd->fetchObject($query);
$result = str_replace(array("enum('", "')", "''"), array('', '', "'"), $result->Type);
$arr = explode("','", $result);
return $arr;
}
Loop through the result array, and there you've got your select with all posible options:
<?
$cats = $page->getCategories();
foreach ($cats AS $cat) {
echo '<option value="'.$cat.'" '.($page->category == $cat?"selected":"").'>'.$cat.'</option>';
}
?>
$cats = $page->getCategories();
foreach ($cats AS $cat) {
echo '<option value="'.$cat.'" '.($page->category == $cat?"selected":"").'>'.$cat.'</option>';
}
?>