【发布时间】:2023-03-31 21:50:02
【问题描述】:
我几乎已经设法让寻呼工作了。 我想向用户显示找到的记录总数以及当前显示的记录。例如:
4000 found, displaying 0-100.
我正在使用 nr 2 进行测试(因为我没有那么多记录,只有 20 条)。
所以我使用LIMIT $start, $nr_results;
为了以我想要的方式显示结果,我是否必须进行两次查询,一次查询获取所有记录,然后进行 mysql_num_rows 以获取所有记录,然后是具有 LIMIT 的查询?
我有这个:
mysql_num_rows($qry_result);
$total_pages = ceil($num_total / $res_per_page); //$res_per_page==2 and $num_total = 2
if ($p - 10 < 1) {
$pagemin=1;
}
否则{ $pagemin = $p - 10; } 如果($p + 10 > $total_pages){ $pagemax = $total_pages; } 别的 { $pagemax = $p + 10; }
这里是查询:
SELECT
mt.*,
fordon.*,
boende.*,
elektronik.*,
business.*,
hem_inredning.*,
hobby.*
FROM classified mt
LEFT JOIN fordon ON fordon.classified_id = mt.classified_id
LEFT JOIN boende ON boende.classified_id = mt.classified_id
LEFT JOIN elektronik ON elektronik.classified_id = mt.classified_id
LEFT JOIN business ON business.classified_id = mt.classified_id
LEFT JOIN hem_inredning ON hem_inredning.classified_id = mt.classified_id
LEFT JOIN hobby ON hobby.classified_id = mt.classified_id
ORDER BY modify_date DESC
LIMIT 0, 2
谢谢,如果您需要更多信息,请告诉我。
基本上 Q 是,我必须进行两次查询吗?
【问题讨论】:
标签: php sql mysql pagination