MySQL Sort related issues

Source: Internet
Author: User
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;
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.