Storing data + array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Storing data + array

Post by Jim_Bo »

Hi

I will explain this the best I can, basically I am curious if its pluasable to store and call post data like so:

I have a form with fields like so

name, description, picture, gallery, filter

then there are another 4 text fields across by 8 down ie:

a a1 a2 a3 a4
b b1 b2 b3 b4 b5
c c1 c2 c3 c4 c5 c5
etc
etc

I was thinking about storing each row as one field in the database seperated by a symbol so I can explode the data when I need to call on it and echo it ie:

$sql = "INSERT INTO products (name, description, picture, gallery, data1, data2 etc..) VALUES
('$name', '$description', '0', '$gallery, '$a|$a1|$a2|$a3|$a4', '$b|$b1|$b2|$b3|$b4');

Im thinking that this would make for less work when inserting and calling on the data, or would I be better off inserting each text field posted into its own field within the table?

Thanks
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

A better idea would be to create another table and use a foreign key to map the individual values to the main table on a one to many basis :)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

well, it has its pros & cons, i would say if the items are small lengthwise, then this may be a solution...
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Basically the first field of each row holds the heading, each of the other three fields basically hold data like dimensions & pressure. So each field holds small amounts of different data .. each row being a different product with different specs

how should I got about it?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

use the primary key field of the products table as a foreign key on the data table (data table being the table which contains data1, data2 etc.) :)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Jim_Bo wrote:Basically the first field of each row holds the heading, each of the other three fields basically hold data like dimensions & pressure. So each field holds small amounts of different data .. each row being a different product with different specs

how should I got about it?
If you don't need sorting and other special things you can do so... I have done it sometimes when I had to store user choices which only consisted of 1-9 so it was quite under control. I'm afraid if all the concatenated data gets past the set limit of field, it will get lost without any warning...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hmmz,

I dont know if 2 tables would be needed, I was just thinking more along the lines of cutting the table from 43 odd columns down to 11 odd by performing the task in my first post.

The data held wont need to be searchable or anything, but there is an edit option which I thought explode could be used to read the data back ..

not sure is serialize() would work under this situation?

Which is best .. really im hunting for a way to have less columns in the table .. maybe its best I have a large number of columns?


Thanks
Post Reply