[英]Retrieve from wordpress database with sort
I have a wordpress website, and I'm trying to get the results from a table in alphabetical order (Greek language). 我有一个wordpress网站,我正在尝试从表中按字母顺序(希腊语)获取结果。 I have tried asort, but it does not work.
我尝试过各种各样,但没有用。 I suppose I am missing something, but I cannot figure it out.
我想我缺少了一些东西,但是我无法弄清楚。 Here is the code:
这是代码:
if($homeplayers) {
asort($homeplayers);
$i = 1; foreach ($homeplayers as $homeplayer) {
$output .= '<tr>';
$output .= '<td style="vertical-align:top;word-wrap:break-word;">';
$output .= leagueengine_fetch_player_emblem($homeplayer->player_id).leagueengine_fetch_data_from_id($homeplayer->player_id,'data_value' );
$output .= '</td>';
$output .= '<td style="text-align:center;vertical-align:top;">';
if(isset($_POST['import_last_home_lineups']) && in_array($homeplayer->player_id, $home_app)) {
$output .= '<input class="homeplayers" name="homeplayers[]" type="checkbox" checked="checked" value="'.$homeplayer->player_id.'">';
} else {
$output .= '<input class="homeplayers" name="homeplayers[]" type="checkbox" '.leagueengine_isplaying_tournament($tournament_id,$match_id,$homeplayer->player_id).' value="'.$homeplayer->player_id.'">';
}
$output .= '</td>';
$i++;
}
$output .= '<td></td>';
$output .= '</tr>';
}
You're trying to sort an object, with asort
, but that function has no clue how you want it sorted.... you need a custom sorting function 您正在尝试使用
asort
对对象进行排序,但是该函数不知道如何对其进行排序。...您需要自定义排序函数
usort($homeplayers, "sorter");
function sorter($a,$b){
// assuming ->player_name is the correct variable
return strcmp($a->player_name, $b->player_name);
}
Sources: other question and php docs 资料来源: 其他问题和php文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.