Php 按id但向后调用db行
我正在建立一个链接投票网站,在链接被第二次投票后,这个公式可以正常工作,问题是当链接只有1票时,它会从最旧到最新向后显示 我想要的是一票链接显示从最新到最旧。这是调用首页中链接的行:Php 按id但向后调用db行,php,mysql,Php,Mysql,我正在建立一个链接投票网站,在链接被第二次投票后,这个公式可以正常工作,问题是当链接只有1票时,它会从最旧到最新向后显示 我想要的是一票链接显示从最新到最旧。这是调用首页中链接的行: $articles = Article::getAll("order by ranking desc limit $offset, $num_items"); 这是getAll函数代码: static function getAll($conditions = ' ') { /* Retr
$articles = Article::getAll("order by ranking desc limit $offset, $num_items");
这是getAll函数代码:
static function getAll($conditions = ' ')
{
/* Retrieve all the records from the
* database according subject to
* conditions
*/
$db = null;
$results = null;
$records = array();
$query = "select id, created, modified, username, url, title, description, points, ranking from articles $conditions";
try
{
$db = parent::getConnection();
$results = parent::execSql($query);
while($row = $results->fetch_assoc())
{
$r_id = $row['id'];
$r_created = $row['created'];
$r_modified = $row['modified'];
$r_title = $row['title'];
$r_description = $row['description'];
if(!get_magic_quotes_gpc())
{
$r_title = stripslashes($r_title);
$r_description = stripslashes($r_description);
}
$r_url = $row['url'];
$r_username = $row['username'];
$r_points = $row['points'];
$r_ranking = $row['ranking'];
$article = new Article($r_title, $r_description , $r_url, $r_username, $r_created, $r_modified);
$article->id = $r_id;
$article->points = $r_points;
$article->ranking = $r_ranking;
$records[] = $article;
}
parent::closeConnection($db);
}
catch(Exception $e)
{
throw $e;
}
return $records;
}
如果有人能帮忙,我将不胜感激。将
创建日期添加到订单
条款中怎么样
$articles = Article::getAll("order by ranking desc, created desc limit $offset, $num_items");
将created
日期添加到order
子句中怎么样
$articles = Article::getAll("order by ranking desc, created desc limit $offset, $num_items");
我会照David说的做,只是如果你想让最新的链接先排序,那么你必须按降序添加“created”列:
$articles = Article::getAll("order by ranking desc, created DESC limit $offset, $num_items");
我会照David说的做,只是如果你想让最新的链接先排序,那么你必须按降序添加“created”列:
$articles = Article::getAll("order by ranking desc, created DESC limit $offset, $num_items");