Any suggestions on how I can simplify the php script below?This was my previous question: http://stackoverflow.com/questions/2712237/how-to-check-if-a-checkbox-radio-button-is-checked-in-php that is linked to this one, What I'm trying to do here is to output the data depending on the checkbox that is checked. But my code isn't really good, it shows 2 tables if the condition is met by the 2 results. As you can see in the code below, any suggestions on how I can simplify this?
$id = mysql_real_escape_string($_POST['idnum']);
if ( $_POST['yr'] == 'year' and $_POST['sec'] == 'section' ){
$result2 = mysql_query("SELECT * FROM student WHERE IDNO='$id'");
echo "<table border='1'>
<tr>
<th>IDNO</th>
<th>YEAR</th>
<th>SECTION</th>
</tr>";
while($row = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td>" . $row['IDNO'] . "</td>";
echo "<td>" . $row['YEAR'] . "</td>";
echo "<td>" . $row['SECTION'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
if ( $_POST['yr'] == 'year' and $_POST['sec'] == 'section' and $_POST['lname'] == 'lastname'){
$result3 = mysql_query("SELECT * FROM student WHERE IDNO='$id'");
echo "<table border='1'>
<tr>
<th>IDNO</th>
<th>YEAR</th>
<th>SECTION</th>
<th>LASTNAME</th>
</tr>";
while($row = mysql_fetch_array($result3))
{
echo "<tr>";
echo "<td>" . $row['IDNO'] . "</td>";
echo "<td>" . $row['YEAR'] . "</td>";
echo "<td>" . $row['SECTION'] . "</td>";
echo "<td>" . $row['LASTNAME'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($con);
?>