Basically, is it faster to have a table with 8 columns to go through, or is it faster to have a single one with the values separated by "," (like "a,b,c,d,e,f,g,h") and then let PHP sort them with explode(',',$string)?
Thanks.
Basically, is it faster to have a table with 8 columns to go through, or is it faster to have a single one with the values separated by "," (like "a,b,c,d,e,f,g,h") and then let PHP sort them with explode(',',$string)?
Thanks.
Write a script and benchmark both as the result will depend entirely what your doing.
I'm thinking performance difference will be negligible since you're talking 8 fields. Now if it were hundreds of columns that would be another story...
Depends on the implementation and future requirements. It may look simple to have multiple columns initially under a single entry, but later on you may need to increase the size of it, or sort the multiple columns etc. and that won't be fast nor easy to manage.
Really, you should always store structured data in the proper form in SQL (i.e. by using columns). While I agree that using PHP Explode may be quicker than SQL when dealing with smaller (tiny) amounts of data, you loose all of the query goodness that SQL has to offer. Besides, there are many different SQL solutions out there. Don't just default to MySQL.
Cheers
Jonny
Storing your data in 8 different columns is a lot more flexible. If you run a search for database normalization you'll find a lot of articles explaining the reasons.
my idea is one field and explode this columns.
ok test it and see speed both ;)
and then you understand my idea is true...
Please don't combine 8 different pieces of data into a single database column. That violates basic database design. Each piece of data should be represented as it's own column. That way, you can get at each item individually, or all together, depending on what you're doing.
You're even doing the wrong way... the wrong way..
Why would you use explode when you would just serialize an array then save it, retrieve and unserialize. good way to break your content.
There are times where I've done similar things, moreso for storing settings, pulling 1 column and unserializing is faster and more reliable. what happens if you explode using , and you somehow have a comma in your input..
But again.. since you're sorting results it seems like... follow proper practces, otherwise you'll do something you think is acceptable in another area, and lose your career... or indirectly kill a kitten.. or both.
Hey, what's faster... pouring your own drink, or asking someone else to pour it for you.