Columns in my database: stat_id, stat1, stat2, stat3.
I am using a form that allows me to loop through a list of members and input 3 different stats each. ($member_stat is an array already that includes 'stat_id' as one of its keys)
foreach($member_stats as $member_stat) {
echo '<label for="stat1"> Stat 1</label>';
echo '<input type="text" name="'.$member_stat['stat_id'].'stat1" id="stat1" />';
echo '<label for="stat2"> Stat 2</label>';
echo '<input type="text" name="'.$member_stat['stat_id'].'stat2" id="stat2" />';
echo '<label for="stat3"> Stat 3</label>';
echo '<input type="text" name="'.$member_stat['stat_id'].'stat3" id="stat3" /><br />';
}
I hit submit and my $_POST array/data looks like this:
Array (
[157stat1] = 1
[157stat2] = 4
[157stat3] = 7
[158stat1] = 2
[158stat2] = 2
[158stat3] = 6
[159stat1] = 8
[159stat2] = 6
etc...
)
My questions is: How do I take this $_POST array and insert it into my database as above? ie.
157 stat1 stat2 stat3
158 stat1 stat2 stat3
159 stat1 stat2 etc...
I have tried various things but am having a tough time wrapping my head around separating the stat_id from the different stats in the $_POST keys (ie: 157 from stat1, stat2, stat3). I am wondering if maybe I set it up wrong in the form and should be naming my inputs in some other way.