将查询结果合并到数组中

时间:2015-03-22 11:00:55

标签: mysql wordpress

我有一个数据库查询

 `$select_top = $wpdb->get_results($wpdb->prepare( "SELECT * FROM `wp_top_voted` WHERE `todays_date`= CURDATE() ORDER BY `number_votes` DESC LIMIT 10"));`

我希望将结果放在数组中,使其看起来像$ids = array(49968, 49993, 34711); 我已完成foreach($select_top as $select_top_one){ $ids = array($select_top_one->post_id);,但这会将数组打印为Array ( [0] => 49968 ) Array ( [0] => 49993 ) Array ( [0] => 34711 ) 如何将这些结果放在$ids = array(49968, 49993, 34711);

形式中

1 个答案:

答案 0 :(得分:1)

使用$ids[] = $select_top_one->post_id

foreach($select_top as $select_top_one){ 
    $ids[] = $select_top_one->post_id;
}
print_r( $ids );