鍍金池/ 問答/PHP/ 請(qǐng)問我現(xiàn)在有三條數(shù)據(jù),里面有一條是bid_status=1的,我要怎么只展示為1

請(qǐng)問我現(xiàn)在有三條數(shù)據(jù),里面有一條是bid_status=1的,我要怎么只展示為1的,反之如果都不等于1

請(qǐng)問我現(xiàn)在有三條數(shù)據(jù),里面有一條是bid_status=1的,我要怎么只展示為1的,反之如果都不等于1,就展示全部等于0的,屬于php的,打印出來的數(shù)據(jù)是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
        }
    ],

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

            // 商家的報(bào)價(jià)針對(duì)該用戶以外的用戶屏蔽
            $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) ? "暫無報(bào)價(jià)" : $arr ;
回答
編輯回答
好難瘦

你這個(gè)應(yīng)該在SQL里面去做
先COUNT 一下 bid_status = 1的數(shù)量 如果大于0 就取出 對(duì)應(yīng)數(shù)據(jù)
如果COUNT==0 就取出 bid_status=0 的對(duì)應(yīng)數(shù)據(jù)

2018年4月18日 01:03
編輯回答
話寡

用一個(gè)相反的思路呢?如果獲取是為0的,你就刪除數(shù)組中為1的,獲取為1的,刪除為0的。

2017年11月6日 04:17