MySQL sort problem
MySQL queries a list of data that is paginated, say, 5 records, one page.
$page = $_request[' page '];
SELECT * from User limit ($page-1) *5,5;
Then the array of queries is for example $user_list and then loops the User_list
foreach ($user _list as $k = + $v) {
Then a new field cc is calculated based on a function such as AA
$user _list[$k [' cc '] = AA ($v [' id ']);
}
Then want to follow cc this field to sort the user table encountered the problem is that the list is the first page of pagination sort is normal from small
To the big sort but click on the second page to sort the entire data from small to large rather than as a whole
CC is a frequently changed field, cannot be stored in the database must be calculated to ask you what a good solution
------to solve the idea----------------------
Using the Create temporary table temp
Create a temporary table, and then save the CC as a field in temp, then sort the temporary table, paging.
------to solve the idea----------------------
You calculate only the part of the data that you read, but the effect of the sort is not expected.
If you need to sort by distance, you can do this:
It is assumed that the table has X, Y fields that store the latitude and longitude of the merchant separately.
$x, $y represents the latitude and longitude of the user
There is a select * from the user
ORDER by ABS ($x-X), ABS ($y-y) limit ($page-1) *5,5;