To summarize from a previous question, the user selected a starting date, an ending date, and a region. From these choices, an array of weeks and regions are created, and users enter values ("points") that correspond to a particular week and region. This is what it looks like right now (some parts are hard-coded for testing purposes):
$date_array = Array("01/01/2012", "01/08/2012", "01/15/2012");
$region_array = Array("NYC", "DC");
<form name="test_form" id="test_form" method="post">
<table border="1">
<tr>
<td></td>
<?php
foreach ($date_array as $date)
{
echo "<td>".$date."</td>";
}
?>
</tr>
<?php
foreach ($region_array as $region)
{
echo "<tr>";
echo "<td>".$region."</td>";
foreach ($date_array as $date)
{
echo '<td><input type="text" name='.$region."-value1_".$date.'><input type="text" name='.$region."-value2_".$date.'></td>';
}
echo "</tr>";
}
?>
</table>
<input type="submit" name="submit">
And the next part:
if (isset($_POST['submit']))
{
foreach ($_POST as $k=>$v)
{
if ($k != "submit") // use even and odd count to differentiate TRP and CPP
{
// split the form input on _
$input = explode("_", $k);
echo "<BR>Region: " . $input[0];
echo "<BR>Date: " . $input[1];
echo "<BR>Value: " . $v;
}
echo "<br/>";
}
}
So basically, in this example it outputs 12 times:
Region: NYC-value1 Date: 01/01/2012 Value: 500 Region: NYC-value2 Date: 01/01/2012 Value: 5 Region: NYC-value1 Date: 01/08/2012 Value: 600
I want to catch the value1
and value2
while the loop is running, but as it stands it loops through both of them before going onto the next date/region. My idea, as I put in comments, was to have a counter of even and odd numbers and simply tell if it was doing value1
or value2
based on that.
Is this a good idea or am I missing something fundamentally simpler?