Build Your Own Arcade Controls Forum

Main => Everything Else => Topic started by: cholin on March 28, 2005, 07:39:00 pm

Title: Website SQL
Post by: cholin on March 28, 2005, 07:39:00 pm
I know this isnt usually something you'll see asked around here, but this is the most active forum I know, and this is the "Everything Else" subforum, so here goes.

I have a table in SQL with a row in it named "value".  Now, this row is an ENUM with the options of 0 - 6, which is expressed as ENUM(0,1,2,3,4,5,6).  Now, I need to get "0,1,2,3,4,5,6" into PHP.  Example:

ENUM(0,1,2,3,4,5,6,7,8,9,10) in SQL, I will receive "0,1,2,3,4,5,6,7,8,9,10" in PHP.
ENUM(0,1,2,3,4)                     in SQL, I will receive "0,1,2,3,4"                     in PHP.

DOES ANYBODY KNOW HOW TO DO THIS, PLEASE TELL ME IM GETTING SO STRESSED!
Title: Re: Website SQL
Post by: screaming on March 29, 2005, 03:51:38 pm
I have a table in SQL with a row in it named "value".  Now, this row is an ENUM with the

  I think you mean "column", not "row".

options of 0 - 6, which is expressed as ENUM(0,1,2,3,4,5,6).  Now, I need to get "0,1,2,3,4,5,6" into PHP.  Example:

ENUM(0,1,2,3,4,5,6,7,8,9,10) in SQL, I will receive "0,1,2,3,4,5,6,7,8,9,10" in PHP.
ENUM(0,1,2,3,4)                     in SQL, I will receive "0,1,2,3,4"                     in PHP.

  I've read this post 5 times and I have no idea what you're asking. ENUM fields just define a set of valid values.. I can't think of an instance where you need to get them all enumerated like that. Please tell me specifically what you're trying to do in PHP. magic_quotes can be a hassle when you're doing db stuff in PHP.. I have no idea, but maybe that's what your problem is?

-sab
Title: Re: Website SQL
Post by: cholin on March 29, 2005, 03:59:01 pm
You know how you can define a column type as INT, ENUM, VARCHAR and stuff, but thats not all.  What you really define them as is INT(5), ENUM('0','1','2'), VARCHAR(255).  Notice the numbers in brackets?  I need to get those values into PHP.  So what I want to do, is query the database and find out what is in those brackets.

I found out there is no function to do this, there's mysql_field_type, but that returns "ENUM", not the stuff within the brackets.  Thanks anyways, I guess.  Off to email whoever made PHP!
Title: Re: Website SQL
Post by: rchadd on March 29, 2005, 06:42:09 pm
never heard of ENUM data type - i've only used Oracle

assume its a MySQL specific data type

take a look here http://dev.mysql.com/doc/mysql/en/enum.html

unfortunately still no clearer to me
Title: Re: Website SQL
Post by: cholin on March 29, 2005, 06:47:17 pm
Quote
"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 second column of the output."

Really....  ;D  I don't know why I didnt think of this, but hey, its usually easier for other people to find your mistakes/problems when you're frustrated.  If this works, you are my hero!

EDIT:  HOLY SH*T, SOMEONE EVEN WROTE THE SCRIPT TO PARSE THEM INTO AN ARRAY!  I LOVE YOU SO MUCH!
Quote
Posted by Willem-Jan van Dinter on May 24 2003 4:14pm   [Delete] [Edit]

If you want to get an array in php with all possible values for an ENUM or SET column, you should use: SHOW COLUMNS FROM table_name LIKE 'enum_column_name' (with or without %-wildcards), and parse it with the following php script:

$result=mysql_query($query);
if(mysql_num_rows($result)>0){
$row=mysql_fetch_row($result);
$options=explode("','",preg_replace("/(enum|set)\('(.+?)'\)/","\\2",$row[1]));
}

Now $options is an array with all possible values

Hope it helps.
Title: Re: Website SQL
Post by: rchadd on March 29, 2005, 07:06:12 pm
glad i could be of assistance