在 php 方面,每个人都需要一点帮助 ia noob :(
在我的数据库中,我有一个名为 movies 的表,其中有 12 列,但我使用 2 个列来对我的电影进行排序,其中一个名为 year,另一个是 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";
我希望有人能帮帮忙
谢谢