Posted by Norman Peelman on 12/25/06 22:07
"Stef" <stef.php@gmail.com> wrote in message
news:45900325$0$21505$ba620e4c@news.skynet.be...
> Does anyone have more ideas on this?
>
> "Stef" <stef.php@gmail.com> schreef in bericht
> news:458d2d87$0$21489$ba620e4c@news.skynet.be...
> >I was wondering if it is possible to load the values of a ENUM out of
> >antoher table.
> >
> > Example:
> >
> > Table 1
> > id Colors
> > 1 A
> > 2 B
> > 3 C
> >
> > Table 2
> > id car color
> >
> > Would it be possible to set 'color' to an ENUM type and load the
different
> > values of color out of table 1?
> >
> > Thanks for any ideas.
> >
>
>
I think what you need to do is 'read' in the ENUM definition for the
current 'color' and the ALTER it with the new info, something like:
1) read the enum column definition into an array using "SHOW COLUMNS FROM
<table> LIKE '<enum_column>'"
2) add the new values to the array, creating your query, you need to
recreate the entire ENUM column
3) "ALTER TABLE <table> MODIFY enum_column ENUM('?','?'.etc)" where the '?'
are your old and new enum values.
Definately make a copy of your table to test on... or just create a simple
test table to play with until you get it to work.
Link: http://dev.mysql.com/doc/refman/4.1/en/enum.html
....read all the user comments and you'll see what you need to do.
Especially the post by Willem-Jan van Dinter which I tried out while writing
this responce.
Once you have the current ENUM values in an array ($options in this case)
you can create a new query as such:
$options[] = 'newvalue1'; // tack new values onto end of array to preserve
current table data
$options[] = 'newvalue2';
//etc.
$query = "ALTER TABLE <tabel> MODIFY color ENUM(";
$count = 0;
foreach($options AS $val)
{
if ($count == 0)
{
$query .= "'$val'"; // take notice of quotes - must add single quotes back
in
}
else
{
$query .= ",'$val'"; // precede 2nd through last entries with a comma
}
$count++;
}
$query .= ')';
----
Norm
--
FREE Avatar hosting at www.easyavatar.com
[Back to original message]
|