mysql 查询出一个数据列表 这个数据列表是分页的 比如说5个记录一页
$page = $_REQUEST['page'];select * from user limit ($page-1)*5,5;
然后查询的数组比如说为$user_list 然后循环这个user_list
foreach($user_list as $k=>$v){ // 然后根据某函数比如说 aa 计算出一个新的字段cc $user_list[$k]['cc'] = aa($v['id']);}
然后想按照cc这个字段排序user表 遇到的问题是 列表是分页的 第一页排序是正常 从小
到大排序 但是点击第二页又会出现从小到大排序 而不是已整体为依据 排序整个数据
cc 是经常变的字段,不能存到数据库 必须经由计算得出 请教一下大家有什么好的解决方法
回复讨论(解决方案)
可以在查询的时候把你的计算公式aa嵌套进语句中算出CC(如果aa不太复杂的话) 然后直接按CC排序即可
可以在查询的时候把你的计算公式aa嵌套进语句中算出CC(如果aa不太复杂的话) 然后直接按CC排序即可
但是比如说我写的这个sql distance的值就计算不出来$sql = "select id,avg_point,name,xpoint,ypoint,index_img,dp_count,deal_cate_id,ratio,note ,".intval(GetDistance($ypoint,$xpoint,'ypoint','xpoint')*1000)." as distance from ".DB_PREFIX."supplier_location where ".$where;
//把你的aa函数写成mysql的函数,然后用sqlselect *,aa(id)cc from table order by cc desc;
//把你的aa函数写成mysql的函数,然后用sqlselect *,aa(id)cc from table order by cc desc;aa函数是自己写的一个函数 实现特定的功能 mysql里没有
那应该怎么实现像这样的msyql自定义函数 aa(变量1,变量2,表字段1,表字段2)
那应该怎么实现像这样的msyql自定义函数 aa(变量1,变量2,表字段1,表字段2)
//你的aa函数就要4个变量select *,aa(变量1,变量2,字段1,字段2)cc from table order by cc desc;
http://www.baidu.com/s?wd=mysql%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0&rsv_spt=1&issp=1&f=8&rsv_bp=0&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=3&rsv_sug4=97&rsv_sug1=3&rsv_sug2=0&inputT=2568
使用create temporary table temp
创建一个临时表,然后把cc计算好后作为字段保存在temp中,然后再对临时表排序,分页。
使用create temporary table temp
创建一个临时表,然后把cc计算好后作为字段保存在temp中,然后再对临时表排序,分页。
你只对读取到的部分数据进行了计算,当然排序的效果就不是预期的了
如果你是需要按距离排序,那么可以这样做:
假定表中有 X、Y 字段分别保存有商家的经纬度
$x、$y 表示用户的经纬度
则有 select * from user ORDER BY abs($x-X), abs($y-Y) limit ($page-1)*5,5;
一定要全部??排序後再分?。否?就不能??了。

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
