我已經創建了一個數據庫。在那個數據庫中,我創建了一個表格。然後我寫下面的代碼來從創建的表中檢索數據。我檢索了表中存在的所有元素。現在我想將複選框添加到檢索列的所有行中。任何人都可以幫助我,並建議在下面的代碼中的更改。如何在php中將複選框添加到從數據庫檢索到的數據中
<?php
// Check connection
if ($link === false) {
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt select query execution
$sql = "SELECT * FROM fruits";
if ($result = mysqli_query($link, $sql)) {
if (mysqli_num_rows($result) > 0) {
echo "<table>";
echo "<tr>";
echo "<th>PID</th>";
echo "<th>Fruit Name</th>";
echo "<th>Quantity(Kgs)</th>";
echo "<th>Price</th>";
echo "</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['PID'] . "</td>";
echo "<td>" . $row['Fruit Name'] . "</td>";
echo "<td>" . $row['Quantity(Kgs)'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row["submitted"] . "<td><input type ='checkbox' value = '" . $row['PID '] . "'PID = '" . $row['PID '] . "'> </td></td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else {
echo "No records matching your query were found.";
}
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
它看起來像你是*添加複選框。究竟是什麼問題? – David
你不能嵌套''就像你爲複選框做的一樣。如果您打開了一個,請在打開另一個之前將其關閉。 –
你真的需要*'*'嗎? – BenM