MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 8th, 2007, 08:12 PM
michael879 michael879 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 2 michael879 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 26 sec
Reputation Power: 0
Arrays in MySQL

Im currently setting up a database in which there are users, and then each user can have any number of codes. These are two seperate tables, each with private keys. I recently found out that it is impossible to store arrays in tables however (which would be the simple way to do this; an array of code keys in each user record)

The only other way I can think of to do this is to put a user key in the code records to represent the owner. However, this seems to complicate things a little. Is there any other way?

Reply With Quote
  #2  
Old January 9th, 2007, 02:10 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 223 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 2
If you mean:

[table1]
uid / user
[1] user1
[2] user2

[table2]
user_id / code
[1] code1
[1] code2
[1] code3
[2] code4
[2] code5
[...]

then you're ok. The only way to store arrays in one field is by using delimiters, ie:

[1] code1,code2,code3

but you'll need more php to admin this, so go with relational. Check out the JOIN syntax.

Reply With Quote
  #3  
Old January 9th, 2007, 07:58 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
It's true that one field can't really hold multiple pieces of data nicely, but I wouldn't say it's impossible to store arrays. You just need to handle the data a little bit differently.

Humanetainit has a great example above.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #4  
Old January 9th, 2007, 04:38 PM
michael879 michael879 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 2 michael879 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 26 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
It's true that one field can't really hold multiple pieces of data nicely, but I wouldn't say it's impossible to store arrays. You just need to handle the data a little bit differently.

Humanetainit has a great example above.


yea, thats what Im currently doing. I was wondering if there was a simpler way, since this is pretty confusing.

heres another problem Im having:

I have an album table and a song table. each album has multiple songs and each song can be in multiple albums. Its a many to many relationship. Whats the best way to connect these? Currently, I have a string in each album that is a list of all the song ids in the album.

Reply With Quote
  #5  
Old January 10th, 2007, 02:50 AM
Humanetainit's Avatar
Humanetainit Humanetainit is offline
Beyond help
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: The Netherlands
Posts: 223 Humanetainit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 1 h 32 m 30 sec
Reputation Power: 2
Administration of a normalized db is much easier, but SELECTs get more complicated and slower. The most important thing is to keep SELECTs as simple and fast as possible on the client (visitor) side. If this means that administrators need multiple UPDATEs or DELETEs, so be it.

Personally, I use heavy recursive functions containing SELECTs, something you can only do on a production server if you write the outcome to a file (server side caching).

You might even use a database cache: copy your data to a database that is optimized for SELECTs, but administrate the normalized one... I've never tried it, could be a pain.

Whatever you do, minimize database queries for your visitors.

Reply With Quote
  #6  
Old January 10th, 2007, 07:55 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Quote:
Originally Posted by michael879
heres another problem Im having:

I have an album table and a song table. each album has multiple songs and each song can be in multiple albums. Its a many to many relationship. Whats the best way to connect these? Currently, I have a string in each album that is a list of all the song ids in the album.


To satisfy the many-to-many relationship you are portraying... I would use a database structure similar to the following.

Code:
ALBUMS
------
id, title

SONGS
-----
id, title, artist

ALBUM_SONG
-------------
album_id, song_id

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Arrays in MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway