Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

retrieve enum values
Hi!

I have a column type enum in mysql.
At the moment the possible values are 1,2 and 3.

I make a form for my user to modify that value, something like:
<select>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
</select>

I may need to add a value 4 to the enum, and in that case I would like to
avoid modifying the code.

I would like to know it it is possible to have something like:
select possible_enum_values from table ...
and then having a loop through these values.
I can't select distinct values in that column because one value may not
exist yet and I don't want to have fake records.

I found that in the mysql doc and was wondering if there is an already
implemented php function intsead of having to parse:
" If you want to determine all possible values for an ENUM column, use SHOW
COLUMNS FROM tbl_name LIKE enum_col and parse the ENUM definition in the
second column of the output."

Any idea?

Melanie

 ________________________________________
_________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger

Report this thread to moderator Post Follow-up to this message
Old Post
Mel List_php
04-14-05 08:55 PM


Re: retrieve enum values
$descRS = mysql('describe theTableName theEnumColumn');
list($fld_name, $fld_type, $fld_null, $fld_key, $fld_default, fld_extra) =
mysql_fetch_row($descRS);
mysql_free_result($descRS);

// Values you will be interested: $fld_type (and $fld_default perhaps)
// $fld_type will be equal to = enum('1', '2', '3')

$enumValuesArr = split(',', str_replace("'", "", substr($fld_type, 5, -1)));

echo '<select>';

foreach ($enumValuesArr as $enumValue) echo "<option
value='$enumValue'>$enumValue</option>"

echo '</select>';

-----------------------------------------

Hope it gonna help!

Regards,
Nadim Attari,
Alienworkers.com
-----------------------------------------

> Hi!
>
> I have a column type enum in mysql.
> At the moment the possible values are 1,2 and 3.
>
> I make a form for my user to modify that value, something like:
> <select>
> <option value='1'>1</option>
> <option value='2'>2</option>
> <option value='3'>3</option>
> </select>
>
> I may need to add a value 4 to the enum, and in that case I would like to
> avoid modifying the code.
>
> I would like to know it it is possible to have something like:
> select possible_enum_values from table ...
> and then having a loop through these values.
> I can't select distinct values in that column because one value may not
> exist yet and I don't want to have fake records.
>
> I found that in the mysql doc and was wondering if there is an already
> implemented php function intsead of having to parse:
> " If you want to determine all possible values for an ENUM column, use
SHOW
> COLUMNS FROM tbl_name LIKE enum_col and parse the ENUM definition in the
> second column of the output."
>
> Any idea?
>
> Melanie

Report this thread to moderator Post Follow-up to this message
Old Post
Nadim Attari
04-15-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP DB archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:10 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.