Here is my PHP code:
<?php
include ('../connection.php');
$query00 = mysql_query("SELECT * FROM ta_subjects WHERE USER_ID='$login_session' AND Subject_ID='00000001'",$connection);
while ($row00 = mysql_fetch_array($query00))
{
$thisSub[] = $row00['TopicName'];
}
$arrlength = count($thisSub);
?>
<!--=====Math=======-->
<div class="tab-content">
<div id="math" class="tab-pane fade in active"><br>
<?php
include '../connection.php';
$query = mysql_query("SELECT * FROM topics WHERE SubjectID = '1'",$connection);
while ($row = mysql_fetch_array($query))
{
$sub1 = $row['TopicName'];
?>
<div class="col-sm-6">
<?php
$a=0;
do
{
if($thisSub[$a] == $sub1)
{
?>
<input type="checkbox" class="sub" name="checklist1[]" value="<?php echo $sub1;?>" disabled checked>
<?php
$a = $a + 1;
}
else
$a = $a + 1;
}while($arrlength == $a);
?>
<input type="checkbox" class="sub" name="checklist1[]" value="<?php echo $sub1;?>" disabled>
<label><?php echo $sub1;?></label>
</div>
<?php
}
?>
</div>
I am comparing the list of all subjects from the database and the subjects with the same ID from the database also and mark it as checked. But it only displays the first checked check box and ends the loop. So the only checked check box is only Algebra. What am I missing here?
Solved
Solved it by putting the second check box in the else block instead of under the while loop as what @dreamster suggested.