Multi table pagination
If you have the following function: How to add LIMIT sequence for each table ?
function find($page=2,$num_of_page=30){
$query_1 = "SELECT COUNT(*) FROM table_1";
$query_2 = "SELECT COUNT(*) FROM table_2";
$query_3 = "SELECT COUNT(*) FROM table_3";
.
.
.
/*
$total_count == 100;
$table_1_count == 33;
$table_2_count == 10;
$table_3_count == 57;
*/
$offset = $page -1 * $num_of_page;
$limit = $num_of_page;
.
.
}
开发者_运维技巧
if $page == 2 and $num_of_page ==30; you should execute
SELECT * FROM table_1 LIMIT 30,3
SELECT * FROM table_2 LIMIT 0,10
SELECT * FROM table_3 LIMIT 0,17
Please forgive my ugly English
If these tables all have the same structure, you could do SELECT * FROM table1 UNION ALL SELECT * FROM table2 UNION ALL SELECT * FROM table3
and then using a single LIMIT
for the query.
精彩评论