Page 1 of 1

Storing data + array

Posted: Wed Oct 26, 2005 5:38 am
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

Posted: Wed Oct 26, 2005 5:46 am
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 :)

Posted: Wed Oct 26, 2005 5:46 am
by n00b Saibot
well, it has its pros & cons, i would say if the items are small lengthwise, then this may be a solution...

Posted: Wed Oct 26, 2005 6:10 am
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?

Posted: Wed Oct 26, 2005 7:12 am
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.) :)

Posted: Wed Oct 26, 2005 7:32 am
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...

Posted: Wed Oct 26, 2005 8:17 am
by John Cartwright

Posted: Wed Oct 26, 2005 5:02 pm
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