PHP Developers Network
http://forums.devnetwork.net/

The way to get enum values from a column
http://forums.devnetwork.net/viewtopic.php?f=19&t=135645
Page 1 of 1

Author:  Jitro [ Sun May 13, 2012 4:11 pm ]
Post subject:  The way to get enum values from a column

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?

Syntax: [ Download ] [ Hide ]
<?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?

Author:  social_experiment [ Tue May 15, 2012 7:57 am ]
Post subject:  Re: The way to get enum values from a column


have a look at this url, it might be helpful

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/