eg . names = ENUM('peter','john','steven')
I have the value 'john' and want to know the index number i.e. is it
1,2,3 where
names[1]='peter'
names[2]='john'
names[3]='steven'
PROBLEM.
I read the string from a table but another table that my system
inherited takes an integer identical to the index of the enum on the
first table. Rather than re - structuring thedatabase which is known to
work without errors I wanna simply enter say 'steven' and have php
return to me either 3 or names[3].
If anyone can do this then I'll shake your hand and give
you a chocholate watch.
Hm, let's see if I've understood what you want. I've got a column called
'problem_severity' in a table called 'problem' in a database called
'tracking'. The column is declared as:
enum('low','medium','severe','showstopper')
The following code makes an associative array mapping the enum's string
values to the integer values:
[no error checking for brevity]
<?php
$db = mysql_connect("localhost", "andyh", "CENSORED");
mysql_select_db("tracking");
$result = mysql_query("show columns from problem like
'problem_severity'");
$types = mysql_result($result, 0, "Type");
echo "Enum values: $types<br><br>";
$types = substr($types, 5, strlen($types)-6);
$i = 1;
foreach (explode(',', $types) as $value) {
$severity[$value] = $i++;
}
foreach ($severity as $key => $value) {
echo "Key: $key; Value: $value<br>\n";
}
?>
The output is:
Enum values: enum('low','medium','severe','showstopper')
Key: 'low'; Value: 1
Key: 'medium'; Value: 2
Key: 'severe'; Value: 3
Key: 'showstopper'; Value: 4
So $severity['medium'] == 2
That anywhere close?
--
Andy Hassall (an...@andyh.org) icq(5747695) http://www.andyh.org
http://www.andyh.uklinux.net/space | disk usage analysis tool