duanquannan0593 2018-02-28 16:48
浏览 21
已采纳

在php中更新mysql表,并为每个受影响的行存储ID [重复]

This question already has an answer here:

I'm trying to use the results of a MySQL select in a php script and make some updates in the same table.

For the following query, I need to look at each record and say "if order_status = 'S', set is_placement to 1 (this is a bit) and set date_updated to curdate()"

I can do that with an update, but the trick is I need to store the order_id of those with the status of 'S' in an array to use in another query.

I'm not sure how I would loop and store those in an array for that.

Here's the select:

$orderCheck = "
    SELECT 
        order_id,
        order_status
    FROM order_status
 ";

EDIT (based on answers below): So I can make an array of order IDs like so:

$result = mysqli_query($connection,$orderCheck);
while ($row = mysqli_fetch_array($result))
    {
        $array = $row['order_id'}
        if($row['order_status'] == 'S'){
        Store ORder IDs here}
    }

But with that array and stored order IDs, I need to update the records for each ID.

How can I preform that update and store the necessary IDs as well?

</div>
  • 写回答

2条回答 默认 最新

  • dt2015 2018-02-28 16:59
    关注

    The following will store the data the way you needed:

    $result = mysql_query($orderCheck);
    $order_ids = array();
    
    while ($row = mysql_fetch_array($result))
        {
        $order_id = $row['order_id'];
        if ($row['order_status'] == "S")
            {
            array_push($order_ids, $order_id);
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF RichTextBox格式化大量文本卡顿如何解决
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥15 pip install后修改模块路径,import失败,需要在哪里修改环境变量?
  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决