I'm going to construct a table to let my user enter their SPM result then my system will filter and show them which course is eligible to apply.
I've tried to make 10 rows in a table and each row consisted of 2 <select>
, one is SPM subject and another one is the grade they obtained. The options of Subject and Grade were fetch from my database.
Here is my coding for my table:
<?php
$result = mysql_query("SELECT * FROM spm_subject");
$result2 = mysql_query("SELECT * FROM spm_grade");
?>
<table class="p1" bgcolor="#FFFFCC" bordercolor="#000000" align="center" width="771" border="2">
<tr>
<td><div align="center"><strong>No.</strong></div></td>
<td><div align="center"><strong>Subject Name</strong></div></td>
<td><div align="center"><strong>Grade</strong></div></td>
</tr>
<form action="checkresult2.php">
<?php
for($i=1; $i<=10; $i++)
{?>
<tr>
<td width="44"><div align="center"><?php echo $i; ?></div></td>
<td width="601">
<select>
<option value="">--- Please choose a subject ---</option>
<?php
while($s = mysql_fetch_assoc($result))
{?>
<option name="subj"><?php echo $s["name"]; ?></option>
<?php } ?>
</select>
</td>
<td width="104"><div align="center">
<select>
<option value=""> </option>
<?php
while($g = mysql_fetch_assoc($result2))
{?>
<option name="grad"><?php echo $g["grade"]; ?></option>
<?php } ?>
</select>
</div>
</td>
</tr>
<?php } ?>
<tr>
<td colspan="3">
<div align="center">
<input type="submit" value="Submit">
</div>
</td>
</tr>
</form>
</table>
The table was constructed but only the FIRST ROW able to display data from the both database tables inside the both <select>
.
Any solution to solve this problem?