Page 1 of 1

The way to get enum values from a column

Posted: Sun May 13, 2012 4:11 pm
by Jitro
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 :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

<?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>';
}

?>
Is it alright?

Re: The way to get enum values from a column

Posted: Tue May 15, 2012 7:57 am
by social_experiment
http://stackoverflow.com/questions/2350 ... l-database
have a look at this url, it might be helpful