The way to get enum values from a column
Posted: Sun May 13, 2012 4:11 pm
Hello,
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
. 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?
Is it alright?
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
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
<?php
//connect to database
require_once('../base.php');
$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);
#print_r($table);
echo 'We have the following ENUM values: ';
foreach($table as $v){
echo '<b>'.$v.' </b>';
}
?>