通过id调用db行但向后调用db行

时间:2009-02-22 18:19:44

标签: php mysql

我正在建立一个链接投票站点,该链接第二次投票后该公式正常,问题是当链接只有1票时它会向后显示,从最旧到最新。

我想要的是一票投票从最新到最旧显示。这是调用首页中链接的行:

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

如果有人可以提供帮助,我会很感激。

2 个答案:

答案 0 :(得分:2)

如何将created日期添加到order条款?

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

答案 1 :(得分:1)

我会做大卫所说的,只是如果你想要最新订购的链接,那么你必须按降序添加“已创建”列:

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