Get 3 row ID's via ARRAY_A

时间:2016-10-28 作者:Hermants

下面的查询工作正常。但我怎么能select the 3 results separately 使用array_number?

我需要在array\\u编号的帮助下将3个结果正确分开。但不知道怎么做。

$records = $wpdb->get_results("
SELECT * FROM wp_rdp_participants_answers AS answ 
INNER JOIN wp_rdp_game_images AS game ON game.image_id = answ.image_id
WHERE answ.game_id = $i 
&& answ.answer_time LIKE \'$day%\' 
AND answ.answer = game.correct_answer
ORDER BY answ.answer_time ASC 
LIMIT 3", ARRAY_A);

if(count($records) > 0){
    foreach($records as $rec){      

    echo $rec->user_id.\' - \'. $rec->answer_time.\' - \'.$rec->answer.\' - \'. $rec->correct_answer. \'<br>\' ;
    }
}

How do I get now array[0] , array[1], array[2] ?

1 个回复
最合适的回答,由SO网友:TheDeadMedic 整理而成

Errm...

$item_1 = $records[0];
$item_2 = $records[1];
$item_3 = $records[2];

// e.g.
echo $item_2->answer_time;

相关推荐

为‘TAX_QUERY’=>ARRAY()输出术语数组

我正在尝试使用后端的自定义字段在前端的类别归档的WP\\U查询中设置分类法。在页面模板中。这将从自定义字段中获取我的类别:$terms = get_field(\'add_categories_custom_template\', $term->term_id); if( $terms ): foreach( $terms as $term ): echo $term; echo \',\'; endforeach; endi