我的代碼有問題。我有一個充滿 SQL 資料的表。如果 Barva = 1,我想讓我的復選框被選中,如果 Barva = 0,則取消選中。
我嘗試在<?php if ($row['status'] == 1) { echo "checked='checked'"; } ?>兩者之間添加此代碼,<td contenteditable="false"><form method="post"><input type="checkbox" name = checkbox'.$row[ID].'></form></td>但語法失敗。
有人能幫助我嗎?
索引- 這是它的樣子
SQL - sql 視圖
$output = '
<br />
<table >
<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" >'.$row["SerialNumber"].'</td>
<td contenteditable="true">'.$row["Produkt"].'</td>
<td contenteditable="true">'.$row["Oddělení"].'</td>
<td contenteditable="true" >'.$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;
?>
uj5u.com熱心網友回復:
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" >'.$row["SerialNumber"].'</td>
<td contenteditable="true">'.$row["Produkt"].'</td>
<td contenteditable="true">'.$row["Oddělení"].'</td>
<td contenteditable="true" >'.$row["Místnost"].'</td>
<td contenteditable="true">'.$row["IP"].'</td>
<td contenteditable="true">'.$row["USB"].'</td>
<td contenteditable="true">'.$row["Datum"].'</td>
</tr>
';
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/324922.html
上一篇:將請求作為日期
下一篇:BASH程式員
