Bluehost.com Web Hosting $6.95

mysql_field_type() ...

This is a discussion on mysql_field_type() ... within the PHP General forums, part of the PHP Programming Forums category; ....will say if a field is of type "ENUM", but not its possible values (including default). Does anyone ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-03-2003
René fournier
 
Posts: n/a
Default mysql_field_type() ...

....will say if a field is of type "ENUM", but not its possible values
(including default). Does anyone know how I can fetch possible values
of a field type of ENUM?

Thanks.

....Rene
Reply With Quote
  #2 (permalink)  
Old 11-03-2003
Rob Adams
 
Posts: n/a
Default Re: mysql_field_type() ...

"René fournier" <m5@renefournier.com> wrote in message
news:D9DBDF2D-0E2F-11D8-A33D-0003931DAC94@renefournier.com...
> ...will say if a field is of type "ENUM", but not its possible values
> (including default). Does anyone know how I can fetch possible values
> of a field type of ENUM?


desc $tbl_name;

You'll have to parse it, but it will give you the list of available values.


>
> Thanks.
>
> ...Rene

Reply With Quote
  #3 (permalink)  
Old 11-07-2003
David Robley
 
Posts: n/a
Default Re: mysql_field_type() ...

In article <D9DBDF2D-0E2F-11D8-A33D-0003931DAC94@renefournier.com>,
m5@renefournier.com says...
> ...will say if a field is of type "ENUM", but not its possible values
> (including default). Does anyone know how I can fetch possible values
> of a field type of ENUM?
>
> Thanks.
>
> ...Rene
>

Try this little function which I use as an include file; there are
possibly other and/or better ways to do it. Watch out for linewrap :-0

<?php
function mysql_fetch_enums( $link, $table_name, $field_name ){
/* Takes a connection link identifier, MySQL table name and field name for
an enum type field
Returns an associative array containing the enum values as both key and
value,ready to feed
to dropdown.inc; or 0 on error */
global $database;
mysql_select_db($database);
$mysql_datatype_field = 1;
if (!$result = mysql_query ("SHOW COLUMNS FROM $table_name LIKE
'$field_name'", $link ) ){
$output=0;

echo mysql_error();
} else {
$mysql_column_data = mysql_fetch_row( $result );
if ( !$enum_data= $mysql_column_data[$mysql_datatype_field] ){
$output=0;
} else if ( !$buffer_array=explode("'", $enum_data) ){
$output = 0;
} else {
$I = 0;
reset ($buffer_array);
while (list(, $value) = each ($buffer_array)) {
if( $I % 2 ) $output[stripslashes($value)] =
stripslashes($value);
++$I;
}
}
}
return $output;
}
?>

--
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:26 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0