Re: adding to functionality of mysql_fetch_field

From: Date: Wed, 14 Mar 2001 20:30:24 +0000
Subject: Re: adding to functionality of mysql_fetch_field
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-43909@lists.php.net to get a copy of this message
On Wed, 14 Mar 2001 12:12:22 -0800, Dennis Gearon (gearond@oit.edu) wrote: >I'd like to see mysql_fetch_field() return as the last value in the >object, the allowable values for an enum field as an array. Could I >get >a cc as well as a listserver group answer from the PHP guys as to >whether they think this is a good idea? > >Is there any other EASY way to get that information about a field? > >It would make making <select> inputs a lot easier and more tied to >the >database without thinking by the programmer, and would track design >changes to the database. you can do something like this: $result=mysql_query("describe $table"); while($row=mysql_fetch_array($result)){ if($row["Field"]==$fieldname){ $enum=$row["Type"]; break; } } $enum will look something like: "enum('Yes','No')" then you parse out $enum to get the values. put it in a function called get_enum_values($table,$fieldname) and youre all set. maybe there's an easier way but I don't know of it.

« previous php.general (#43909) next »