2 回答

TA貢獻1773條經驗 獲得超3個贊
如果您想要生成的所有復選框的唯一名稱,您可以通過$i為每一行遞增來獲得它們。
res = $db->query($query);
if ($res->num_rows > 0) {
$i = 0;
while ($row = $res->fetch_object()) {
$query = "SELECT * FROM device_status
WHERE device = ($row->id)";
$status = $db->query($query);
$device_status = $status->fetch_object();
$content .= <<<END
<tr>
<td>{$row->devices}</td>
<td>{$row->description}</td>
<td>{$row->room}</td>
<td><input type='radio' name='radiobutton<?php echo $i?>' id='myCheck'></td>
<td><input type='radio' name='radiobutton<?php echo $i?>' id='myCheck' checked='checked'></td>
<!-- <td>{$device_status->status}</td> -->
<td><a href="delete-device.php?id=$row->id">Delete</a>
<a href="edit-device.php?id=$row->id">Edit</a></td>
</tr>
END;
$i++;
}
}
echo $content;

TA貢獻1810條經驗 獲得超4個贊
如果您不關心單選按鈕的名稱,您可以使用“php 隨機數生成器”,每一行您為單選按鈕名稱分配一個新的隨機數:
<?php $x = rand(5, 100000); ?> <input type='radio' name='<?php echo $x; ?>' id='myCheck'>
- 2 回答
- 0 關注
- 121 瀏覽
添加回答
舉報