因此,我在PHP表中有一个访客列表,但是我想检查已到达的访客。
$sql='SELECT * FROM guestlist LIMIT ' . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($connect, $sql);
echo "<table><tr><th>ID</th><th>Name</th><th>Surname</th><th>Check-in</th></tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $row["id"]. "</td>
<td>" . $row["name"]. "</td>
<td> " . $row["surname"]. "</td>
<td><input type='checkbox' class='get_value' name='checkbox' ".$row["check-in"]. "></td>
<td><input type='submit' name='submit' value='submit' ".$row["submit"]. "></td>
</tr>";
}
echo "</table>";
答案 0 :(得分:2)
我不知道$row['check-in']
包含什么,但是您只需要使用html checked
:
if($row["check-in"]=='on'){
$checked=" checked='checked'";
}else{
$checked='';
}
echo "<td><input type='checkbox' class='get_value' name='checkbox' ".$checked."></td>";
编辑:在循环中使用:
echo "<td><input type='checkbox' class='get_value' id='checkbox[]' name='checkbox[]' ".$checked."></td>";