我从db获取日期以在下拉菜单中显示日期。它基于id显示。我想根据日期对数据进行排序。我现在按以下顺序获取日期:
Saturday, March 25
Saturday, April 15
Wednesday, April 5
Saturday, May 6
Saturday, April 29
Wednesday, May 10
Saturday, May 20
我需要以下顺序的数据:
Saturday, March 25
Wednesday, April 5
Saturday, April 15
Saturday, April 29
Saturday, May 6
Wednesday, May 10
Saturday, May 20
代码
$dates = \Drupal::service('custom_forms.custom_forms_service')->getDates();
$datesObj = array("" =>"- Select -");
foreach($dates as $date){
$datesObj[$date->id] = $date->date;
echo "<pre>";print_r($datesObj[$date->id]);
}
exit;
答案 0 :(得分:0)
SELECT id, name, form_id, DATE(updated_at) as date
FROM wp_frm_items
WHERE user_id = 11 && form_id=9
ORDER BY updated_at DESC,id ASC
这将首先按日期对记录进行排序,然后按名称对记录进行排序 More detail