The way to get enum values from a column

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Forum Newbie
Posts: 5
Joined: Sun Sep 12, 2010 7:43 pm

The way to get enum values from a column

Post by Jitro »


I was looking for a script to get items from ENUM column in MySQL. I found some LONG, EXTENSIVE scripts on how to do it on the Internet. Those scripts used a variety of functions and variables. I didn't even understand it :lol: . I took the idea from those scripts and created a script on my own - concise and short.

Now, I wonder at how short it is in comparison with those ones on the Internet. What do you think of my script?

Code: Select all


//connect to database

$query = "show columns from goods like 'producer'";

$r = mysqli_query($connect, $query);

$row = mysqli_fetch_array($r);

$en = $row['Type'];

//change every unwanted character to nothing. 
$table = array('enum'=>'',','=>' ','('=>'',')'=>'',"'"=>'');

$en2 = strtr($en,$table);

$table = explode(" ",$en2);

echo 'We have the following ENUM values: ';

foreach($table as $v){
echo '<b>'.$v.' </b>';

Is it alright?
User avatar
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: The way to get enum values from a column

Post by social_experiment » ... l-database
have a look at this url, it might be helpful
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply