请问我现在有三条数据,里面有一条是bid_status=1的,我要怎么只展示为1的,反之如果都不等于1

打飞机的猪猪侠
  • 24

请问我现在有三条数据,里面有一条是bid_status=1的,我要怎么只展示为1的,反之如果都不等于1,就展示全部等于0的,属于php的,打印出来的数据是json,不用管格式

"baojia": [

        {
            "bid_price": "*****",
            "bid_status": "0",
            "store_logo": "https://img.qcpjpt.com/20180818/1534584899_792.png",
            "store_name": "我要入驻",
            "store_credit": 0
        },
        {
            "bid_price": "*****",
            "bid_status": "0",
            "store_logo": "https://img.qcpjpt.com/20180814/1534238896_521.jpg",
            "store_name": "永丰汽配",
            "store_credit": 0
        },
        {
            "bid_price": "*****",
            "bid_status": "1",
            "store_logo": "https://img.qcpjpt.com/Public/uploads/20180530/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20180530140423.jpg",
            "store_name": "华航通宝",
            "store_credit": 100
        }
    ],

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

            // 商家的报价针对该用户以外的用户屏蔽
            $arr = [];
            $arr_ = [];
            foreach ($quoted_price as $key => $value) {
                if( $request->param("user_id") != $reg['user_id'] ){
                    $arr[$key]['bid_price'] = "*****";
                } else {
                    $arr[$key]['bid_price'] = $value['bid_price'];
                }
                if( $value['bid_status'] == 0 ){
                    $arr[$key]['bid_status'] = '0';
                } else {
                    $arr[$key]['bid_status'] = '1';
                }
                $arr[$key]['store_logo'] = $value['store_logo'];
                $arr[$key]['store_name'] = $value['store_name'];
                $arr[$key]['store_credit'] = $value['store_credit'];
                if( !empty($value['bid_status']) == 1 ){
                    $arr_ = $value['bid_status'];
                }
            }
            $data["baojia"] = empty($arr) ? "暂无报价" : $arr ;
回复
阅读 1k
2 个回答

你这个应该在SQL里面去做
先COUNT 一下 bid_status = 1的数量 如果大于0 就取出 对应数据
如果COUNT==0 就取出 bid_status=0 的对应数据

用一个相反的思路呢?如果获取是为0的,你就删除数组中为1的,获取为1的,删除为0的。

宣传栏