[英]How to get the right max id and min id from a function?
I had a large table with 3 million rows before, but I split it to 6 tables 500.000 rows each, now I'm trying to connect them, but I want to read 1 table by 1 not all 6 tables at the same time, I'm trying to use my website pagination to select which table needs to be read and with which max id and min id. 我以前有一个有300万行的大表,但是我将其拆分为6个表,每个表500.000行,现在我正尝试连接它们,但是我想用1而不是全部6个表同时读取1个表,我正在尝试使用我的网站分页来选择需要读取的表格以及最大ID和最小ID。
I made this function: 我做了这个功能:
$content['data']['max_table'] = 6;
$content['data']['min_table'] = 1;
$content['data']['limit_page'] = 100;
function Tables( $start_num, $end_num ) {
global $content;
if($end_num <= 500000) {
$Table_Number = $content['data']['max_table'];
} else if($end_num > 500000) {
$Calc = intval($end_num/500000);
$Table_Number = $content['data']['max_table']-$Calc;
}
$Array = array();
$Array['Table_Number'] = $Table_Number;
$Array['Max_ID'] = ($Table_Number*500000)-$end_num;
$Array['Min_ID'] = ($Array['Max_ID']-$content['data']['limit_page'])-$start_num;
return $Array;
}
This function gives me the right Table_Number, but Max_ID and Min_ID are wrong. 这个函数给我正确的Table_Number,但是Max_ID和Min_ID是错误的。
Page limit is 100, if my page number 1 = $start_num is 1 and $end_num is 100 and Table_Number is 6 here Max_ID needs to be 3000000 and Min_ID need to be 2999900 页数限制为100,如果我的页码1 = $ start_num为1,$ end_num为100,Table_Number为6,则Max_ID必须为3000000,Min_ID必须为2999900
if page number is 5000 = $start_num is 499901 and $end_num is 500000 and Table_Number is 6 here Max_ID needs to be 2500101 and Min_ID need to be 2500001 如果页码是5000 = $ start_num是499901和$ end_num是500000且Table_Number是6,则Max_ID必须为2500101,Min_ID必须为2500001
if page number is 5001 = $start_num is 500001 and $end_num is 500100 and Table_Number is 5 here Max_ID needs to be 2500000 and Min_ID need to be 2499900 如果页码是5001 = $ start_num是500001并且$ end_num是500100并且Table_Number是5,则Max_ID必须为2500000,Min_ID必须为2499900
... ...
I want to show via Order id Desc 我想通过订单ID Desc显示
Table 6:
Max id = 3000000
Min id = 2500001
Table 5:
Max id = 2500000
Min id = 2000001
How can I get the right Max_ID and Min_ID from this function so I can select the right way? 如何从此函数中获取正确的Max_ID和Min_ID,以便选择正确的方法?
Try this: 尝试这个:
$Array['Min_ID'] = 6 * 500000 - $end_num + 1;
$Array['Max_ID'] = $Array['Min_ID'] + 99;
I successfully fixed the function: 我成功修复了该功能:
function Tables( $start_num, $end_num ) {
global $content;
if($end_num <= 500000) {
$Table_Number = $content['data']['max_table'];
} else if($end_num > 500000) {
$Calc = intval($end_num/500000);
$Table_Number = $content['data']['max_table']-$Calc;
}
$Table_Extra = $content['data']['max_table']-$Table_Number;
if($Table_Extra == 0) {
$Max_Table_ID = $Table_Number*500000;
$Min_ID = ($Max_Table_ID-$end_num)+1;
$Max_ID = $Min_ID+99;
} else if($Table_Extra > 0) {
$Add_Extra = $Table_Extra*500000;
$Max_Table_ID = $Table_Number*500000;
$Min_ID = (($Max_Table_ID-$end_num)+1)+$Add_Extra;
$Max_ID = ($Min_ID+99)+$Add_Extra;
}
$Array = array();
$Array['Table_Number'] = $Table_Number;
$Array['Max_ID'] = $Max_ID;
$Array['Min_ID'] = $Min_ID;
return $Array;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.