乾草大家需要幫助IA小白升技的時候纔來的PHP :(排序電影由兩件事情
在我的數據庫,我有一個表叫電影,我有12列在那裏,但我用了2個collumns排序我的電影,有人稱今年另1 imdb_rating
這是我如何對它們進行排序
public function getRealMovies($lang=null, $p=null, $l=null, $sortby=null){
$movies = array();
if (($p) && ($l)){
$start = ($p-1)*$l;
$limit = " LIMIT $start,$l";
} else {
$limit = '';
}
if (!$sortby || $sortby=='abc'){
$order = "ORDER BY title ASC";
} elseif ($sortby=='date'){
$order = "ORDER BY date_added DESC";
} elseif ($sortby=='imdb_rating'){
$order = "ORDER BY imdb_rating DESC";
} elseif ($sortby=='year'){
$order = "ORDER BY year DESC";
}
$e = mysql_query("SELECT * FROM movies WHERE id IN (SELECT movie_id FROM movie_embeds) $order $limit") or die(mysql_error());
if (mysql_num_rows($e)>0){
$ids = array();
while($s = mysql_fetch_array($e)){
$movies[$s['id']] = $this->formatMovieData($s, $lang);
$ids[] = $s['id'];
}
if (count($ids)){
$flags = $this->getFlags($ids);
if (count($flags)){
foreach($movies as $movie_id => $val){
if (array_key_exists($movie_id,$flags)){
$movies[$movie_id]['languages'] = $flags[$movie_id];
} else {
$movies[$movie_id]['languages'] = array();
}
}
}
}
}
return $movies;
}
是否有可能通過兩件事情,例如整理
} elseif ($sortby=='imdb_rating and year'){
$order = "ORDER BY imdb_rating and year DESC";
我希望有人能幫助
感謝
它沒有工作,它只能通過imdb_rating排序,而不是按任何其他想法 –