嗨,我从一个数据库中回显了多行。每一行都有一个选择框,它回显当前与该行相关的字段中的内容。
通过选择框,我可以选择一个不同的选项。提交时没有发生任何事情,没有错误。它应该做的是更新这些字段。我以前从未更新过多行,所以这对我来说是新的。
下面的第一个查询是我试图实现的更新,用order\u 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>
我需要做什么来更新每一行的订单号?
暂无答案!
目前还没有任何答案,快来回答吧!