2 回答

TA貢獻1815條經(jīng)驗 獲得超6個贊
不反對這個問題的解決方法,按照上面的方法,order by在原來的sql中添加就可以解決問題。但是我想我有分頁一個更好的做法:使用參數(shù)一樣has_more,last_product_id并limit_num與服務器連接的客戶端。
has_more指示服務器中是否有更多數(shù)據(jù); last_product_id表示上次響應數(shù)據(jù)的id; limit_num表示每頁的數(shù)量。
這樣,客戶端可以使用has_more,以確定發(fā)送請求或沒有,如果是,則客戶機發(fā)送請求與last_product_id和limit_num給服務器; 對于服務器,sql 可以是這樣的:
select * from table where id < $last_product_id order by id desc
limit $limit_num + 1; =>$datas
而且,計數(shù)($ DATAS)和$ limit_num計算的價值has_more和last_product_id:
$has_more = 0;
$data_num = count($datas);
if ($data_num > $page_limit) {
$has_more = 1;
array_pop($datas);
$data_num--;
}
$last_product_id = end($datas)['id'] ?? 0;

TA貢獻1860條經(jīng)驗 獲得超8個贊
SELECT *, COUNT(product.id) AS 'count' FROM product INNER JOIN product_category on product.product_category_id = product_category.id INNER JOIN company_manufacturer_product on product.company_manufacturer_product_id=company_manufacturer_product.id group by product.id OFF SET 6 0;
添加回答
舉報