note 10074 deleted from function.mysql-field-type by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 02:19:16 +0000 |
| Subject: | note 10074 deleted from function.mysql-field-type by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21815@lists.php.net to get a copy of this message | ||
I've been asked how to get the try MySQL type of fields, presumably so folks could get the
values of sets and enums.
This is what I use (slightly modified):
Function makeSelectList($table,$field){
$s="";
$rid=mysql_query("SHOW COLUMNS FROM $table");
$nr=mysql_num_rows($rid);
while(list($name, $type)=mysql_fetch_row($rid)){
if($name==$field){
if(ereg('^enum\(.*\)$',$type))
$type=substr($type,6,-2);
else if(ereg('^set\(.*\)$',$type))
$type=substr($type,5,-2);
else
return("<option>ERROR");
$opts=explode("','",$type);
while(list($k,$v)=each($opts))
$s.="<option>$v";
}
}
return($s);
}
Use the function as follows:
echo "<form><select
name=\"selectfield\">".makeSelectList('tablename','fieldname')."</select><input
type=\"submit\"></form>";
(I hope my embedded html doesn't get interpreted)