如何使复选框行检查/未检查值1/0从数据库?

  • 本文关键字:数据库 复选框 何使 php ajax
  • 更新时间 :
  • 英文 :


我的代码有问题。我有表填满了SQL数据。我想让复选框在Barva = 1时选中,在Barva = 0时不选中。

我试图在<td contenteditable="false"><form method="post"><input type="checkbox" name = checkbox'.$row[ID].'></form></td>之间添加此代码<?php if ($row['status'] == 1) { echo "checked='checked'"; } ?>,但语法失败。

有人能帮我一下吗?索引-这是它的样子

SQL - SQL view

$output = '
<br />
<table class="table table-bordered table-striped">
<tr>
<th width="1%">!</th>
<th width="1%">ID</th>
<th width="10%">Inventární číslo</th>
<th width="10%">Serial Number</th>
<th width="10%">Produkt</th>
<th width="10%">Oddělení</th>
<th width="10%">Místnost</th>
<th width="10%">IP</th>
<th width="10%">Síť/USB</th>
<th width="10%">Datum</th>
<th width="10%">Funkce</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$page->checkbox_state = $row["Barva"];  
$output .= '
<tr>
<td contenteditable="false"><form method="post"><input type="checkbox" 
name = checkbox'.$row[ID].'></form></td>
<td contenteditable="true">'.$row["ID"].'</td>
<td contenteditable="true">'.$row["Inventárníčíslo"].'</td>
<td contenteditable="true" class="jmeno">'.$row["SerialNumber"].'</td>
<td contenteditable="true">'.$row["Produkt"].'</td>
<td contenteditable="true">'.$row["Oddělení"].'</td>
<td contenteditable="true" class="jmeno">'.$row["Místnost"].'</td>
<td contenteditable="true">'.$row["IP"].'</td>
<td contenteditable="true">'.$row["USB"].'</td>
<td contenteditable="true">'.$row["Datum"].'</td>
</tr>
';
}
$output .= '</table>';
echo $output;
?>
I think you can use like  below to get checkbox checked:

$output = '
<br />
<table class="table table-bordered table-striped">
<tr>
<th width="1%">!</th>
<th width="1%">ID</th>
<th width="10%">Inventární číslo</th>
<th width="10%">Serial Number</th>
<th width="10%">Produkt</th>
<th width="10%">Oddělení</th>
<th width="10%">Místnost</th>
<th width="10%">IP</th>
<th width="10%">Síť/USB</th>
<th width="10%">Datum</th>
<th width="10%">Funkce</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$page->checkbox_state = $row["Barva"];  
$isChecked="";
if($row["Barva"]==1)
{
$isChecked="checked='checked'";
}
$output .= '
<tr>
<td contenteditable="false"><form method="post"><input type="checkbox" 
name = checkbox'.$row["ID"].' '.$isChecked.'></form></td>
<td contenteditable="true">'.$row["ID"].'</td>
<td contenteditable="true">'.$row["Inventárníčíslo"].'</td>
<td contenteditable="true" class="jmeno">'.$row["SerialNumber"].'</td>
<td contenteditable="true">'.$row["Produkt"].'</td>
<td contenteditable="true">'.$row["Oddělení"].'</td>
<td contenteditable="true" class="jmeno">'.$row["Místnost"].'</td>
<td contenteditable="true">'.$row["IP"].'</td>
<td contenteditable="true">'.$row["USB"].'</td>
<td contenteditable="true">'.$row["Datum"].'</td>
</tr>
';
}

最新更新