php - 根据单选按钮更新 MySQL 数据
问题描述
我现在面临一个挑战。
我有一个返回页面,如果我通过单选按钮选择了第一行,我想将我的订单历史记录表中的history_status从更改为。我这样做的原因是运行查询以仅显示history_status值。"DONE"
"RETURN PENDING"
"DONE"
以下是我正在使用的代码:
<?php
$db = mysqli_connect('localhost','root','','customercaremodule');
date_default_timezone_set('Asia/Kuala_Lumpur');
$FBdate = date("Y-m-d H:i:s");
$sql = "SELECT p.product_id ,p.product_name , p.price, p.product_description, o.history_id ,o.qty , o.subtotal, o.history_datetime , o.history_status FROM product p, orderhistory o where o.product_id = p.product_id AND o.history_status = 'DONE'";
$result=mysqli_query($db,$sql);
$Cntsql = "SELECT count(return_id) AS total FROM retrn";
$res = mysqli_query($db,$Cntsql);
$value = mysqli_fetch_assoc($res);
$num = $value['total'];
if (isset($_POST['submitbuttonform']))
{
$return_id = $num+1;
$return_status = 'PENDING';
$return_reason = $_POST['reasonselected'];
$return_option = $_POST['returnoption'];
$return_datetime = $FBdate;
$history_id = $_POST['selectitemradio'];
$history_status = "UPDATE orderhistory SET history_status = 'RETURN PENDING'";
$sql = "INSERT INTO `retrn`(`return_id`, `return_status`, `return_reason`, `return_option`, `return_datetime`, `history_id`) VALUES ('$return_id','$return_status','$return_reason','$return_option','$return_datetime','$history_id')";
$sql = "INSERT INTO 'orderhistory'('history_status') VALUES ('$history_status')";
$result=mysqli_query($db,$sql);
解决方案
从您的代码 $history_id = $_POST['selectitemradio']; 我假设您从页面中获取历史 ID。
因此,您可以在 where 子句中使用 history_id。现在只有选定的行将被更新。
UPDATE orderhistory SET history_status = 'RETURN PENDING' where history_id=$history_id
推荐阅读
- r - Group the near same numbers of a vector
- image - 使用 .txt 文件中的 URL 图像列表使用 ffmpeg 创建延时视频
- amazon-s3 - 在 S3 与 Elastic Beanstalk 中托管 Docker 容器?
- laravel - 从控制器中的 url 获取 id 值并显示关联 laravel 的值
- r - 后处理 R Markdown 生成的 html 文件
- node.js - googleapis 驱动器无法访问共享驱动器文件
- tensorflow - Tensorflow:沿张量轴的最大值的二进制掩码
- json - PySimpleGUI 中从右到左的文本方向
- python - 使用替换组合后,如何删除包含我不想要的组合的元组
- swift - 使用 .init(suitename:) 时,对 NSUserDefaults 的观察不起作用