Laravel 4:自定义选择查询

时间:2014-08-31 10:02:28

标签: php mysql laravel laravel-4

我使用Laravel DB :: select 从DB返回特定数据,

使用print_r($ result)

时,问题只有一行返回
    $questions = DB::select('
            select text
            from question 
            where id in (?) 
            order by field(id,?)',
            array($question_ids_list_str,$question_ids_list_str));


    print_r($questions);

如何返回剩下的结果? 感谢,

2 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情:

$ids = array(1, 2, 3); // Pass the ids in whereIn clause
$questions = DB::table('question')
               ->whereIn('id', $ids) 
               ->orderBy('id')
               ->get(array('text')); // Only get text field

答案 1 :(得分:0)

试试这个:

$questions = DB::select('
        select text
        from question 
        where id in (?) 
        order by field(id,?)',
        array($question_ids_list_str,$question_ids_list_str));
foreach($questions as $question) {
    echo $question;
}