Hi friends what is the best way to show the mysql enum values while inserting and updating php page ?
name ENUM('small', 'medium', 'large')
edited: actually I was asking for this . I have a database field
`color` enum('red','blue','green','white') DEFAULT NULL,
and php form
<label for="color">Colors</label><br />
<input type="text" name="color" />
How do i display enum value on the php form from mysql database? Please help
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 Type column of the output.
ENUM values are sorted based on their index numbers, which depend on the order in which the enumeration members were listed in the column specification. For example, 'b' sorts before 'a' for ENUM('b', 'a') . The empty string sorts before nonempty strings, and NULL values sort before all other enumeration values.
The ENUM data type in MySQL is a string object. It allows us to limit the value chosen from a list of permitted values in the column specification at the time of table creation. It is short for enumeration, which means that each column may have one of the specified possible values.
First of all, in order to save enum values in a relational database using JPA, you don't have to do anything. By default, when an enum is a part of an entity, JPA maps its values into numbers using the ordinal() method. What it means is that without customizations JPA stores enum value as numbers.
If you have a enum field, the MySQL will return string values for it and you can set with integer and string values too. Simply doing this:
mysql_query("select name from tablename");
will give you full labels like small
or medium
or large
And you can similarly update them too using full labels like this:
mysql_query("insert into tablename (name) values ('small')");
or numeric values like this:
mysql_query("update tablename set name = 2");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With