2016-07-18 139 views
0
matchthese=['name'=> Input::get('name'),]; 
Matchthose['place'=> Input::get('place')]; 
$Select_db = Db::table('actvities') 
       ->where([[matchthese],[matchthose]]) 
       ->orwhere('place', Input::get('place')) 
       ->orwhere('color', Input::get('color')) 
       ->orwhere('people',Input::get('people')) 
       ->get(); 

但是这个地方不能正常工作。我想要第一个或第二个等等。我应该怎么做这个工作?建筑物基于输入的查询

+0

第一个完美的作品,但是当我只选择四种颜色中的一种,姓名,地点和人物,例如,如果我选择人们去的地方或人的地方它问我的名字或给我错误的结果可以请别人告诉我为什么 ? – user3353610

+0

您需要更清楚您当前的结果以及您的预期产出。目前,你想要什么是模棱两可的。 “我想要第一个还是第二个”你是说你只想要一个结果,而不是一个集合?你的意思是什么?它给了你'错误的结果'。举一个例子,说明你正在得到什么样的结果和你期望的结果 – ExoticChimp

+0

我想要一个查询被执行或者每次执行一个查询时根据我的用户选择执行查询,这可能是地点和颜色的组合,或者只是颜色我想要这种关系。我不确定我的代码是否正确 – user3353610

回答

1

您可以使用skiptakefirst

例如,对于第一个可以直接使用first

$Select_db = Db::table('actvities') 
       ->where([['name', '=', Input::get('name')],['place', '=', Input::get('place')]]) 
       ->orwhere('place', Input::get('place')) 
       ->orwhere('color', Input::get('color')) 
       ->orwhere('people',Input::get('people')) 
       ->take(1)->first(); 

对于第二个:

$Select_db = Db::table('actvities') 
       ->where([['name', '=', Input::get('name')],['place', '=', Input::get('place')]]) 
       ->orwhere('place', Input::get('place')) 
       ->orwhere('color', Input::get('color')) 
       ->orwhere('people',Input::get('people')) 
       ->skip(1)->take(1)->first(); 

如果您需要要循环浏览结果,您只需使用foreach

$Select_db = Db::table('actvities') 
       ->where([['name', '=', Input::get('name')],['place', '=', Input::get('place')]]) 
       ->orwhere('place', Input::get('place')) 
       ->orwhere('color', Input::get('color')) 
       ->orwhere('people',Input::get('people')) 
       ->get(); 
foreach($Select_db as $record) { 
    //Do something with $record. 
} 

我希望这会帮助你。

+0

非常感谢你我会尝试它,但我的问题是我的地方不正常工作,我需要例如第一个被执行的地方是正确的但是,例如,当我只选择输入的地方时,这个地方没有执行,这让我想起了名字? – user3353610

+0

请查看更新的答案! –