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条)

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀