新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
php如何實(shí)現(xiàn)兩張不同的表分頁(yè)

本文操作環(huán)境:windows7系統(tǒng)、php7.1版、DELL G3電腦
php 如何實(shí)現(xiàn)兩張不同的表分頁(yè)?
PHP 跨表分頁(yè)
當(dāng)兩表數(shù)據(jù)相對(duì)均衡的情況下比較適用
$min_b || empty($b_f)) # b組數(shù)據(jù)小 重新查詢(xún)a組
{
# 查出偏移量
# 第二次查詢(xún) second
$a_s = getRangeInfo($a, $min, $max_a); # second 第二次查找
# 求出新查出的數(shù)據(jù)與最開(kāi)始查出a數(shù)組相差個(gè)數(shù)
$offset = count($a_s)-$a_f_len;
} else { # a組數(shù)據(jù)小 重新查詢(xún)b組
# 查出偏移量
$b_s = getRangeInfo($b, $min, $max_b);
# 求出新查出的數(shù)據(jù)與最開(kāi)始查出a數(shù)組相差個(gè)數(shù)
$offset = count($b_s)-$b_f_len;
}
}
$now_position = $show = (int)($averge*2-$offset);
$start_position = $page*$page_size;
$end_position = ($page+1)*$page_size-1;
// 假如一次查詢(xún)某數(shù)組為空,查詢(xún)的第二組數(shù)據(jù)未能涵蓋所需全部數(shù)據(jù),故重新查詢(xún)
$a_s = getlimit($a, $min, $start_position-$now_position+$page_size);
$b_s = getlimit($b, $min, $start_position-$now_position+$page_size);
$total_arr = array_merge($a_s, $b_s) ;
sort( $total_arr); # 升序排列
$res = [];
foreach ($total_arr as $k=>$v) {
if ($now_position > $end_position) {
break;
}
if ($now_position < $start_position){
$now_position = $now_position+1;
continue;
}
$now_position = $now_position+1;
$res[] = $v;
}
// 思路如下:
$min_str = $min_a > $min_b ? ' 最小數(shù)在b, 重新獲取a數(shù)據(jù)'.json_encode($a_s):'最小數(shù)在a, 重新獲取b數(shù)據(jù)'.json_encode($b_s);
print_r('數(shù)組$a:'.json_encode($a));
echo '
';
print_r('數(shù)組$b:'.json_encode($b));
echo '
';
print_r('平均數(shù)floor is '.$averge.', $a 最小值是 '.$min_a.',$b 最小值是 '.$min_b.', 對(duì)比之后得出最小值是'.$min.','.$min_str.
'此時(shí)偏移量'.$offset.', 最小數(shù)'.$min.'處于位置'.$show.', 我需要'.$start_position.'到'.$end_position.'的數(shù)據(jù),
查出所需數(shù)據(jù)為'.json_encode($total_arr).', 結(jié)果為'.json_encode($res));
return $res;}// 按值范圍獲取function getRangeInfo ($array, $start_value, $end_value){
sort($array);
$res = [];
foreach ($array as $k => $v)
{
if ($v >= $start_value && $v <= $end_value){
$res[] = $v;
}
}
return $res;}// 按起始位置個(gè)數(shù)獲取function getlimit ($array, $start_value, $num){
sort($array);
$res = [];
foreach ($array as $k => $v)
{
if ($num<=0) {
break;
}
if ($v >= $start_value){
$res[] = $v;
$num --;
}
}
return $res;}$b = [1];$a = [2,3,1,4,5,6,7,8,9,10,12,14];$page = 2; # 第一頁(yè)$page_size = 5;$list = getPage($a, $b, $page, $page_size);$all = array_merge($a, $b);sort($all);echo '
';echo '
';echo '
';$start_position = $page*$page_size;$real = array_slice($all, $start_position, $page_size);print_r('合并總數(shù)據(jù)'.json_encode($all).',一頁(yè)'.$page_size.'條, 第'.(string)($page+1).'頁(yè)數(shù)據(jù)為:'.json_encode($real));
本文名稱(chēng):php如何實(shí)現(xiàn)兩張不同的表分頁(yè)
路徑分享:http://fisionsoft.com.cn/article/dhicgjh.html


咨詢(xún)
建站咨詢(xún)
