dongluojiao6322 2016-08-08 11:20
浏览 85

从foreach的第一个元素中获取结果

There are many matching credentials inside the table which are inserted to an foreach loop however I am getting the results only from the first foreach element. How could I fix that?

    foreach($matches as $match)
    {
        $object = $match->object;

        $sales->whereRaw("match (`object`) against (?)", array($object));

        if($match->colourBase == '1')
        {
            $sales->where('colour', '=', 'CC');
            $sales->orWhere('colour', '=', 'CC+DD');

            if($match->maxPrice)
            {
                $sales->where('price', '<=', $match->maxPrice);
            }

            if($match->minPrice)
            {
                $sales->where('price', '>=', $match->minPrice);
            }
        }
    }

    $results = $sales->orderBy('sales.updated_at', 'asc')->get();

@update

This is how I get $matches

 $matches = Match::where('PeopleID', '=', $id)->get();
  • 写回答

1条回答 默认 最新

  • donglv6747 2016-08-08 13:55
    关注

    If you want only one record use first() function. No need to use foreach. :)

    $matches = Match::where('PeopleID', '=', $id)->first();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver