On Fri, Jun 22, 2001 at 04:45:53PM -0700, Todd A. Jacobs wrote:
> Is there a way to dynamically build an option list from an enum/set type?
> In other words, if I don't know the possible values of the enum or set
> field ahead of time, how can I retrieve that information at run-time?
Here is a function I use to dynamically build an option list. You send
it the table and column. Database and columnType are optional. The
function returns the values of the column as an array.
<?php
function getEnumValues($table, $column, $database="default",
$columnType="enum") {
$mylink = connect();
$sql = "describe $table";
$thisResult = mysql_db_query($database, $sql, $mylink);
while($table = mysql_fetch_array($thisResult)) {
if($table[Field] == $column && $columnType == "enum") {
return explode(",", preg_replace("/^enum\(|'|\)/i", "",
$table[Type]));
}
elseif($table[Field] == $column && $columnType == "set") {
return explode(",", preg_replace("/^set\(|'|\)/i", "",
$table[Type]));
}
}
}
?>
--
Jason Stechschulte
[EMAIL PROTECTED]
--
It is my job in life to travel all roads, so that some may take the road
less travelled, and others the road more travelled, and all have a
pleasant day.
-- Larry Wall in <[EMAIL PROTECTED]>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]