Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

displaying mysql enum values in php

Tags:

php

mysql

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

like image 696
ktm Avatar asked Sep 15 '10 08:09

ktm


People also ask

How can I get enum possible values in a MySQL database?

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.

How do I query enum in SQL?

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.

What is enum data type in MySQL?

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.

How are enums stored in database?

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.


1 Answers

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");
like image 55
shamittomar Avatar answered Oct 03 '22 03:10

shamittomar