Re: how to recognize ENUM column in table?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Lucas wrote:
Afan Pasalic wrote:
Jim Lucas wrote:
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.

-afan

Try 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


Thanks Jim.
But, I was actually looking for column type is like ENUM, with some
differences. And it's SET type.

-afan


I must be missing something else you haven't mentioned, AFAIK this gives you the information that
you are asking for.

The output shows that it is telling you Type = enum(...)

Isn't that what you are asking for?  If it were a set type column, then it would say Type = set(...)

What are the differences that you speak of / request?

Oh.I'm sorry Jim. Yes, you are right.
This was my first email. After this one I asked other one where was looking for column type close to ENUM() and the answer was SET() and I was thinking you replied to that one.

My bad. I apologize.

-afan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux