I am currently trying to figure out why my loop is not working.
Expected behavior:
If a user has already voted (their user_id
is in the vote
table), disable their checkbox.
Result:
Only the first option, person_1
, is disabled.
But if I replace user_id (3) with user_id (2) in the vote table, it will disable the checkbox for person_1, person_2
<?php
$result_userdet = $mysqli->query("SELECT * FROM `user`")
or die($mysqli->error);
$vote = $mysqli->query("SELECT * FROM `vote`")
or die($mysqli->error);
while ($row = $result_userdet->fetch_assoc()) {
if (mysqli_num_rows($vote) == 0) { ?>
<br>
<input type="checkbox" name="user_id[]" value="<?php echo $row['user_id'];?>" > <?php echo $row['user_name'];?></option>
<?php
} else {
$result = $vote->fetch_assoc();
if ($row['user_id'] == $result['user_id']) { ?>
<br>
<input type="checkbox" name="user_id[]" value="<?php echo $row['user_id'];?>" disabled> <?php echo $row['user_name'];?></option>
<?php
}
if ($row['user_id'] != $result['user_id']) { ?>
<br>
<input type="checkbox" name="user_id[]" value="<?php echo $row['user_id'];?>" > <?php echo $row['user_name'];?></option>
<?php
}
}
}
?>