Laravel - 使用前一个SELECT的结果从表中选择全部

时间:2015-01-30 05:22:19

标签: php mysql laravel

我正在尝试在Laravel中执行以下查询,但是在编写DB类和Eloquent类时遇到了麻烦。 我想做类似以下的事情..

$week = DB::select('SELECT week FROM calendar WHERE year = 2015 and month = 01 and day = 30'); $secondResult = DB::select("SELECT * FROM calendar WHERE year = 2015 and week = $week"); return View::make('calendar')->with('weekdays',$secondResult);

1 个答案:

答案 0 :(得分:1)

试试这个..

$week = DB::select('SELECT week FROM calendar WHERE year = 2015 and month = 01 and day = 30');
     foreach ($week as $weekvalue)
{
   echo  $weekname=$weekvalue->week;
}

$secondResult = DB::select("SELECT * FROM calendar WHERE year = 2015 and week = $weekname");
return View::make('calendar')->with('weekdays',$secondResult);