2009-02-22 41 views
0

我正在建立一个链接投票站点,该公式工作正常后,链接投票第二次,问题是,当链接只有1票它显示了倒退,从最旧到最新。通过ID调用db行但向后

我想要的是带有一个投票的链接显示从最新到最旧。这是调用在头版的链接线:

$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; 
    } 

如果有人可以帮助我将不胜感激。

回答

1

我会做大卫说什么,只是,如果你想通过最新的第一个命令的链接,那么你必须按降序添加了“创建”列:

$articles = Article::getAll("order by ranking desc, created DESC limit $offset, $num_items"); 
2

created日期添加到order子句怎么样?

$articles = Article::getAll("order by ranking desc, created desc limit $offset, $num_items");