【问题标题】:How to check checboxes in a php table?如何检查php表中的复选框?
【发布时间】:2019-06-04 08:24:54
【问题描述】:

所以我在 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>";

【问题讨论】:

  • 那里没有显示您的复选框。 ..
  • 您只是在寻找checked 属性的&lt;input type="checkbox" /&gt; 元素吗?
  • 它包含复选框...
  • @megi 不知道有一种叫做 checkboxes 的数据类型...
  • 以后,请格式化您的代码示例,使其易于阅读,如果可能的话,无需滚动到下周查看行尾。这也将使您更容易阅读和调试自己

标签: php ajax checkbox


【解决方案1】:

我不知道$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>";

【讨论】:

  • 只是为了确保它适用于所有浏览器stackoverflow.com/questions/7851868/…
  • 不,它没有帮助我......当我刷新页面时,复选框仍然未选中
  • 您需要将'on' 更改为您在数据库中查找的任何内容
  • @megi 客人到达时$row["check-in"] 包含什么值,客人未到达时包含什么值?
  • 数据签入后是否保存?
猜你喜欢
  • 1970-01-01
  • 2019-10-30
  • 1970-01-01
  • 1970-01-01
  • 2014-02-17
  • 2011-12-22
  • 1970-01-01
  • 1970-01-01
  • 2019-05-29
相关资源
最近更新 更多