Jump to content


Photo

SQL syntax for an array?


  • Please log in to reply
6 replies to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 03 August 2006 - 04:24 AM

Hello,

What is the SQL syntax for an array? I've been searching Google for the past hour, and other has turned up.

Additionally, if someone could tell me how to put like...more than one string into that array, thanks.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 02:13 PM

Huh?  Perhaps you mean an IN clause? Could you give an example?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 03 August 2006 - 07:31 PM

INSERT INTO config (config_name, config_value) VALUES ('allowed_file_ext', '{\.mid, \.mp3, \.wav, \.aiff}');

Where {\.mid, \.mp3, \.wav, \.aiff} is supposed to be the array (each item in the array seperated by a comma), but I don't believe it is working as I want it to.




#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 August 2006 - 07:49 PM

Yeah, there is no such thing... if you're selecting some from a predefined set, you could use ENUM/SET, but it makes more sense to have one record per pair of name/value.  If that doesn't suffice, you'll need to insert some string that can be subsequently parsed, but that's not always better, and much harder to maintain.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 03 August 2006 - 09:41 PM

Try imploding the array into a single string value with some separator that won't cause you problems, and then exploding it when you pull it out of the database again.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 August 2006 - 12:37 AM

That will work, of course -- just consider the long-term implications (i.e. impossible to search properly, hard to edit, etc).
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 GoinNuts

GoinNuts
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationLiberty, MO, USA

Posted 16 August 2006 - 10:11 PM

My suggestion would be to keep the fields in the SQL table as distinct values (as opposed to parsing them into a delimited string). If you need to work with the values in an array within your php code, populate the array from the result of the query on the fly.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users