我有一个问题。我想按desc订购帖子。
case 'posts':
// page header
page_header($system['system_title'].' - '.__("Posts Directory"));
// pager config
require('includes/class-pager.php');
$params['selected_page'] = ( (int) $_GET['page'] == 0) ? 1 : $_GET['page'];
$total = $db->query("SELECT * FROM posts") or _error(SQL_ERROR);
$params['total_items'] = $total->num_rows;
$params['items_per_page'] = $system['max_results'];
$params['url'] = $system['system_url'].'/directory/'.'posts'.'/%s';
$pager = new Pager($params);
$limit_query = $pager->getLimitSql();
// get posts
$rows = array();
$get_rows = $db->query("SELECT post_id FROM posts ".$limit_query) or _error(SQL_ERROR);
while($row = $get_rows->fetch_assoc()) {
$row = $user->get_post($row['post_id']);
if($row) {
$rows[] = $row;
}
}
$smarty->assign('rows', $rows);
$smarty->assign('pager', $pager->getPager());
break;
我可以尝试通过post_id desc订购吗?请帮我的问题。
答案 0 :(得分:1)
在您的query
语句中:
$get_rows = $db->query("SELECT post_id FROM posts ".$limit_query) or _error(SQL_ERROR);
您可以更改为
$get_rows = $db->query("SELECT post_id FROM posts Order By post_id DESC".$limit_query) or _error(SQL_ERROR);
我确实在query
语句get row post
中进行了更改。.因为我也不知道总query
语句和select
语句的用法相同。因此,我建议您为Order By Desc
做Posts
的问题。
答案 1 :(得分:0)
只需将此“ ORDER by {field_name} DESC”添加到您的SQL查询中,例如: “ SELECT * FROM posts ORDER by post_id DESC”