为什么我在WHILE循环上得到NULL

时间:2018-03-07 09:05:29

标签: php

我希望通过支付从商品表订购DESC获取数据。如果商品ID存在于offers_disabled_smart_link表中,请移至下一步并显示链接。我做错了什么?当echo $ link我得到NULL。

我的DeliverService类是:     

class DeliveryService {

    protected $user_id;
    protected $country;
    protected $os;
    protected $ip;
    protected $referrer;
    protected $token;
    protected $smart_link;

    public function __construct($user_id,$country,$ip,$os,$referrer,$token,$smart_link)
    {
        $this->user_id = $user_id;
        $this->user_country = $country;
        $this->user_ip = $ip;
        $this->user_os = $os;
        $this->user_referrer = $referrer;
        $this->user_token = $token;
        $this->smart_link_id = $smart_link;
    }

    public function getStatusOfferSmartLink($offer_id,$smart_link_id,$user_id)

        {
            global $db;
            $sql="SELECT offer_id,smart_link_id,user_id FROM offers_disabled_smart_link WHERE smart_link_id=:smart_link_id AND offer_id=:offer_id and user_id=:user_id";
            $stmp = $db->prepare($sql);  
            $stmp->execute(array(":smart_link_id"=>$smart_link_id,":offer_id"=>$offer_id,":user_id"=>$user_id));
            $results = $stmp->fetchAll(PDO::FETCH_OBJ);
                if($results)
                return true;
            else return false;
        }

    public function deliver()
    {
        global $db;
        $sql="SELECT id, link, payout FROM offers ORDER BY payout DESC";
        $stmp = $db->prepare($sql);  
        $stmp->execute();
        while ($row = $stmp->fetch(PDO::FETCH_ASSOC))  {

                $id = $row['id'];
                $link = $row['link'];


        if($this->getStatusOfferSmartLink($id,$this->smart_link_id,$this->user_id)){
            continue;

        }

        break;
         $this->localFlag = true;


    }
    if ($this->localFlag) {

    return $link;

    }
}

这里我调用函数deliver()和echo $ link

$ad = new DeliveryService(354,$country,$ip,$os,$referrer,$token,$smart_link);
    $link = $ad->deliver();

    echo $link;

如果你想要任何信息,请问我。

1 个答案:

答案 0 :(得分:0)

让我们假设您的查询返回您的预期数据。

$this->localFlag = true;行永远不会在break语句之后执行。 (假设您没有在其他地方设置$this->localFlag。)

改变这个:

break;
$this->localFlag = true;

为:

$this->localFlag = true;
break;

然后试试。希望它能奏效。