2017-01-10 42 views
-4

我不知道如何把我的清單在DESC順序。[PHP]你可以得到這個排序DESC

我試過很多東西,但我仍然有這樣的順序:

function release_year(){ 
global $wpdb; 
$sql = "SELECT DISTINCT `meta_value` FROM `".$wpdb->prefix."postmeta` WHERE `meta_key`='release_year'"; 
$results = $wpdb->get_results($sql); 
return $results; 

這是我得到

 
2016 
2015 
2014 
1988 
2001 
2010 
1998 
... 
+3

_「我嘗試了很多東西」_喜歡什麼?你有沒有嘗試過使用'ORDER BY'? – Chris

+1

'... WHERE'meta_key' ='release_year'order by 1 desc' – bassxzero

回答

1
function release_year(){ 
global $wpdb; 
$sql = "SELECT DISTINCT `meta_value` FROM `".$wpdb->prefix."postmeta` WHERE `meta_key`='release_year' ORDER BY meta_value DESC"; 
$results = $wpdb->get_results($sql); 
return $results;