---- How to pass a multidimensional Array into a database?
JD_Toims - 10:43 am on Dec 14, 2013 (gmt 0)
How did I know swa66 would like their data normalized? LOL -- That being said, I like swa66 and think they're great at coding, even if we have two different styles in some situations and I'm not even going to argue which is better, because with PHP and MySQL so many things are possible and so many things are situational, it could be an indefinite discussion.
Personally, in your situation, I'd prefer to do something along the lines of "as small as possible" single table storage with correlation on the way in/out -- In your system, I'd likely go with something like:
$main_array = array(  => Array ( [name] => John Brown [id] => 123 [awards] => 0 )
 => Array ( [name] => Jim White [id] => 124 [awards] => 1,2 )
 => Array ( [name] => Mike Green [id] => 125 [awards] => 0 ) )
Then associate the "word values" of awards 0, 1, 2, etc. with "human readable values" on-the-way-in and on-the-way-out, which might even end up normalized, but would be, imo [I haven't tested your situation specifically, so I'm not certain], much easier and faster to work with than multiple tables, due to indexing and number of db requests necessary to get the info stored back out and presented to a visitor.
Your foreach() loop could then look something like this:
Keep in mind a foreach() is usually slower than a for(), so if you want to gain a "blip" a for() is usually better -- Also, keep in mind I'm tired, so I could be one loop off [I think I am], but it's time for me to go to sleep, so I'm not going to look at this any more and try to make sure I said what I was thinking the way I thought I wanted to say it :) LOL