Re: how to recognize ENUM column in table?
| From: | Jim Lucas | Date: | Fri, 07 Dec 2007 08:41:18 +0000 |
| Subject: | Re: how to recognize ENUM column in table? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265547@lists.php.net to get a copy of this message | ||
Afan Pasalic wrote:
hi, I use the code from http://www.php.net/manual/en/function.mysql-fetch-field (example #1) I'm getting everything I need but can't recognize if the column is ENUM() type? e.g. column "status" is ENUM('0','1') or ENUM('live','hidden','archive') or something like that. I want to recognize this column and then create a form with radio buttons o 0 o 1 or o live o hidden o archive is it possible? thanks. -afanTry something like this. my table structure was CREATE TABLE
cmsws_com.examples (
col1 ENUM( '0', '1' ) NOT NULL ,
col2 ENUM( 'one', 'two', 'three' ) NOT NULL
) ENGINE = MYISAM
<?php
# setup your db connection and stuff...
$result = mysql_query("SHOW COLUMNS FROM examples");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}
}
My results were
Array
(
[Field] => col1
[Type] => enum('0','1')
[Null] => NO
[Key] =>
[Default] =>
[Extra] =>
)
Array
(
[Field] => col2
[Type] => enum('one','two','three')
[Null] => NO
[Key] =>
[Default] =>
[Extra] =>
)
Hope this fits the bill
--
Jim Lucas
"Perseverance is not a long race;
it is many short races one after the other"
Walter Elliot
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare