Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Website SQL  (Read 989 times)

0 Members and 1 Guest are viewing this topic.

cholin

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 6
  • Last login:July 16, 2009, 09:22:25 pm
    • Nilok Productions
Website SQL
« 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!

screaming

  • Sweet! I'mma go make me some popovers!
  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2124
  • Last login:August 14, 2019, 03:15:34 pm
  • Registered lUser
    • shift eight (*) generation
Re: Website SQL
« Reply #1 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

cholin

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 6
  • Last login:July 16, 2009, 09:22:25 pm
    • Nilok Productions
Re: Website SQL
« Reply #2 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!

rchadd

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1830
  • Last login:June 10, 2013, 06:14:06 am
  • Made in Cornwall
Re: Website SQL
« Reply #3 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
« Last Edit: March 29, 2005, 06:45:09 pm by rchadd »

cholin

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 6
  • Last login:July 16, 2009, 09:22:25 pm
    • Nilok Productions
Re: Website SQL
« Reply #4 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.
« Last Edit: March 29, 2005, 06:49:08 pm by cholin »

rchadd

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1830
  • Last login:June 10, 2013, 06:14:06 am
  • Made in Cornwall
Re: Website SQL
« Reply #5 on: March 29, 2005, 07:06:12 pm »
glad i could be of assistance