嗨,我从数据库中回显了多行。每行都有一个选择框,它会回显该字段中与该行相关的当前内容。
使用选择框,我可以选择其他选项。提交时没有任何反应,没有错误。它应该做的是更新这些字段。我从未尝试过更新多行,所以这对我来说是新的。
下面的第一个查询是我试图通过order_ref更新所有字段的更新
第二个查询只是回显查看所需的所有数据。
<?php
ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
?>
<form>
<table class="tbl-qa">
<thead>
<tr>
<th class="table-header"><p>Action</p></th>
<th class="table-header"><p>Campaign</p></th>
<th class="table-header"><p>Title</p></th>
<th class="table-header" width="100px"><p>Order Reference</p></th>
<th class="table-header"><p>Last updated</p></th>
</tr>
</thead>
<tbody>
<?php
require_once("../db/db_connection.php");
if (isset($_POST['submit'])) {
$sql = $db->prepare("UPDATE articles SET order_ref=? WHERE id=?
");
$order_ref = $_POST['order_ref'];
$sql->bind_param("ii", $order_ref, $_GET["id"]);
if($sql->execute()) {
$success_message = "Edited Successfully";
} else {
$error_message = "Problem in Editing Record";
}
}
$sql = $db->prepare("SELECT * FROM articles WHERE campname=? ORDER BY order_ref ASC
");
$sql->bind_param("s",$_GET["campname"]);
$sql->execute();
$result = $sql->get_result();
?>
<?php
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<tr>
<td class="table-row" width="100px"><div class="edit"><a href="/_admin/edit.php?id=<?php echo $row["id"]; ?>" class="link">Edit</a> |</div><div class="bin"><a href="delete.php?id=<?php echo $row["id"]; ?>" class="link"><img content="delete" id="delete" title="Delete" onclick="return confirm('Are you sure you want to delete?')" src="/_admin/images/delete.png"/></div>
</a>
</td>
<td>
<?php echo $row["campname"]; ?>
</td>
<td class="table-row"><a href="../campaigns/<?php echo str_replace(' ', '-', strtolower($row["campname"])); ?>/page.php?art_url=<?php echo $row["art_url"]; ?>"><?php echo $row["art_title"]; ?></a></td>
<td class="contentedit">
<select name="order_ref">
<option value="<?php echo $row["order_ref"]?>"selected><?php echo $row["order_ref"]?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</td>
<td class="table-row"><?php echo strftime("%b %d, %Y", strtotime($row["last_updated"])); ?></a></td>
<!-- action -->
</tr>
<?php
}
}
else {
echo "No results";
}
?>
<tr class="table-row">
<td colspan="5"><input name="submit" type="submit" value="Update" class="submit"></td>
</tr>
</tbody>
</table>
</form>
我需要做什么才能为回显的每一行更新order_ref?