Hi folks,
I did a search and read through this post but am still a little lost. Basically I have several dynamically named arrays a user can pick on indicators.php...structured like this:
standard
indicatorID[]
method.indicatorID[]
material.indicatorID[]
assessment.indicatorID[]
method, material and indicator arrays all have several checkboxes the user can choose from and are named based on what the indicatorID is. For instance if the user has chosen two indicators (ID 123 and 156) the arrays would be named
method[123]
material[123]
assessment[123]
and
method[156]
material[156]
assessment[156]
I have indicators.php working as it should. indicators.php then calls finish.php which I want to build a table that shows the indicators and the corresponding methods, materials and assessments. Using the above example:
indicator123
method123
method x
method y
material123
material x
material y
assessment123
assess x
assess y
indicator156
method156
method z
material156
material x
material y
assessment156
assess x
assess z
The problem I'm having is that finish.php is putting not differentiating between the indicatorIDs and putting the methods in both. For instance if a user chooses method x for method123 and method z for method156, finish.php builds a table like this:
Indicator123
method123
method x
method z
Indicator156
method156
method x
method z
Here is the code for finish.php...any help is appreciated and sorry if this is a lengthy post.
<?php
if(isset($_POST['indicator']))
{
$output ="";
$output .="<table width='100%' border='1' cellspacing='0' cellpadding='0'>";
foreach ($standard as $s)
{
$standardName="SELECT standard, standardID FROM standards where standardID = " .$s. "";
$resultStandardName = mysql_query($standardName, $dbConn);
while ($row = mysql_fetch_object($resultStandardName))
{
$output .= "<tr bgcolor='#CCCC00'>\n";
$output .= "<td colspan='4'>$row->standard</td>\n";
$output .= "</tr>\n";
foreach ($indicator as $i)
{
$indicatorName="SELECT indicator, indicatorID FROM indicators WHERE indicatorID = " .$i. " AND standardID = " .$s. "";
$resultIndicatorName = mysql_query($indicatorName, $dbConn);
while ($row2 = mysql_fetch_object($resultIndicatorName))
{
$output .= "<tr bgcolor='#99CC99'>\n";
$output .= "<td width='5%'></td>";
$output .= "<td colspan='3'>$row2->indicator</td>\n";
$output .= "</tr>\n";
$output .= "<tr>\n";
$output .= "<td colspan='2' bgcolor='#CCCCCC'></td>";
$output .= "<td colspan='2' bgcolor='#CCCCCC'>Method</td>\n";
$output .= "</tr>\n";
foreach ($_POST['method'] as $m1)
{
$methodName="SELECT method FROM methods WHERE methodID = " .$m1. "";
$resultMethodName = mysql_query($methodName, $dbConn);
while ($row3 = mysql_fetch_object($resultMethodName))
{
$output .= "<tr>\n";
$output .= "<td colspan='3'></td>";
$output .= "<td width='85%'>$row3->method</td>\n";
$output .= "</tr>\n";
} //end while
mysql_free_result($resultMethodName);
} //end foreach
$output .= "<tr bgcolor='#CCCC99'>\n";
$output .= "<td colspan='2'></td>";
$output .= "<td colspan='2' bgcolor='#CCCC99'>Material</td>\n";
$output .= "</tr>\n";
foreach ($materials as $m2)
{
$materialName="SELECT materials FROM materials where materialsID = " .$m2. "";
$resultMaterialName = mysql_query($materialName, $dbConn);
while ($row4 = mysql_fetch_object($resultMaterialName))
{
$output .= "<tr>\n";
$output .= "<td colspan='3'></td>";
$output .= "<td>$row4->materials</td>\n";
$output .= "</tr>\n";
} //end while
mysql_free_result($resultMaterialName);
} //end foreach
$output .= "<tr bgcolor='#CCCCCC'>\n";
$output .= "<td colspan='2'></td>";
$output .= "<td colspan='2' bgcolor='#CCCCCC'>Assessment</td>\n";
$output .= "</tr>\n";
foreach ($assessments as $a)
{
$assessmentName="SELECT assess FROM assessment where assessID = " .$a. "";
$resultAssessName = mysql_query($assessmentName, $dbConn);
while ($row5 = mysql_fetch_object($resultAssessName))
{
$output .= "<tr>\n";
$output .= "<td colspan='3'></td>";
$output .= "<td>$row5->assess</td>\n";
$output .= "</tr>\n";
} //end while
mysql_free_result($resultAssessName);
} //end foreach
$output .= "<tr bgcolor='#CCCC99'>\n";
$output .= "<td colspan='2'></td>";
$output .= "<td colspan='2'>Focus</td>\n";
$output .= "</tr>\n";
foreach ($focus as $f)
{
$focusName="SELECT focus FROM focus where focusID = " .$f. "";
$resultFocusName = mysql_query($focusName, $dbConn);
while ($row6 = mysql_fetch_object($resultFocusName))
{
$output .= "<tr>\n";
$output .= "<td colspan='3'></td>";
$output .= "<td>$row6->focus</td>\n";
$output .= "</tr>\n";
} //end while
mysql_free_result($resultFocusName);
} //end foreach
$output .= "<tr bgcolor='#CCCCCC'>\n";
$output .= "<td colspan='2'></td>";
$output .= "<td colspan='2'>Strategy</td>\n";
$output .= "</tr>\n";
foreach ($strategy as $s)
{
$strategyName="SELECT strategy FROM strategies where strategyID = " .$s. "";
$resultStrategyName = mysql_query($strategyName, $dbConn);
while ($row7 = mysql_fetch_object($resultStrategyName))
{
$output .= "<tr>\n";
$output .= "<td colspan='3'></td>";
$output .= "<td>$row7->strategy</td>\n";
$output .= "</tr>\n";
} //end strategy while
mysql_free_result($resultStrategyName);
} //end foreach
} //end while
mysql_free_result($resultIndicatorName);
} //end foreach
} //end while
mysql_free_result($resultStandardName);
} //end foreach
$output .= "</table>";
} //end if
print $output;
?>
</body>
</html>