為了給你答題,必須得寫(xiě)這么多才能通過(guò)檢查,要不然根本不讓通過(guò)。急用的話直接復(fù)制最后一行代碼即可!
成都創(chuàng)新互聯(lián)主營(yíng)鳳岡網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app開(kāi)發(fā),鳳岡h5小程序定制開(kāi)發(fā)搭建,鳳岡網(wǎng)站營(yíng)銷(xiāo)推廣歡迎鳳岡等地區(qū)企業(yè)咨詢
我看了下,你這個(gè)是需要將正序排列轉(zhuǎn)為倒序排列吧
mysql中的排序是使用 order by 來(lái)排序的,你要根據(jù)什么字段排序,就order by 什么字段
所以這里得用 order by ,例如 order by id asc 就是根據(jù)id正序排序,那么倒序排序呢?
下面我給你貼出答案:
select?id,zh,zcm,time,ts?from?scc?order?by?id?desc;
插入排序(Insertion Sort) 是一種較穩(wěn)定 簡(jiǎn)單直觀的排序算法 插入排序的工作原理 是通過(guò)構(gòu)建有序序列 對(duì)于未排序的數(shù)據(jù) 在有序序列中從后向前掃描 找到合適的位置并將其插入 插入排序 在最好情況下 時(shí)間復(fù)雜度為O(n);在最壞情況下 時(shí)間復(fù)雜度為O(n );平均時(shí)間復(fù)雜度為O(n )
插入排序示例圖
/**
* 數(shù)據(jù)結(jié)構(gòu)與算法(PHP實(shí)現(xiàn)) - 插入排序(Insertion Sort)。Tw.WiNGwit
*
* @author 創(chuàng)想編程(TOPPHP.ORG)
* @copyright Copyright (c) 2013 創(chuàng)想編程(TOPPHP.ORG) All Rights Reserved
* @license /licenses/mit-license.php MIT LICENSE
* @version 1.0.0 - Build20130613
*/
class InsertionSort {
/**
* 需要排序的數(shù)據(jù)數(shù)組。
*
* @var array
*/
private $data;
/**
* 數(shù)據(jù)數(shù)組的長(zhǎng)度。
*
* @var integer
*/
private $size;
/**
* 數(shù)據(jù)數(shù)組是否已排序。
*
* @var boolean
*/
private $done;
/**
* 構(gòu)造方法 - 初始化數(shù)據(jù)。
*
* @param array $data 需要排序的數(shù)據(jù)數(shù)組。
*/
public function __construct(array $data) {
$this-data = $data;
$this-size = count($this-data);
$this-done = FALSE;
}
/**
* 插入排序。
*/
private function sort() {
$this-done = TRUE;
for ($i = 1; $i $this-size; ++$i) {
$current = $this-data[$i];
if ($current $this-data[$i - 1]) {
for ($j = $i - 1; $j = 0 $this-data[$j] $current; --$j) {
$this-data[$j + 1] = $this-data[$j];
}
$this-data[$j + 1] = $current;
}
}
}
/**
* 獲取排序后的數(shù)據(jù)數(shù)組。
*
* @return array 返回排序后的數(shù)據(jù)數(shù)組。
*/
public function getResult() {
if ($this-done) {
return $this-data;
}
$this-sort();
return $this-data;
}
}
?
示例代碼 1
2
3
4
$insertion = new InsertionSort(array(9, 1, 5, 3, 2, 8, 6));
echo '
', print_r($insertion-getResult(), TRUE), '
'; lishixinzhi/Article/program/PHP/201311/20783
多重排序,order by 字段 方式,字段 方式...
order by age desc,id desc 先按年齡降序,相同的年齡里按id降序
order by id,age desc 先按id升序,相同的id里按年齡降序
至于你到底需要什么樣的排序方式,按這個(gè)思路自己寫(xiě)就可以了
樓上說(shuō)的比較正確
?php
首先鏈接你的數(shù)據(jù)庫(kù)
sql="select
*
from
test
order
by
t
desc
limit
0,100"
$ret=mysql_query($sql,$db);//$db為數(shù)據(jù)庫(kù)連接
$zone=1;
while($row=mysql_fetch_array($ret)){
echo
"名次:".$zone.",";
echo
$row['m'];//用戶名
echo
$row['t'];//積分
echo
$row['u'];//序號(hào)
echo
"br/";
}
?
新聞名稱(chēng):php給數(shù)據(jù)庫(kù)排序 php實(shí)現(xiàn)數(shù)據(jù)庫(kù)查詢
網(wǎng)頁(yè)地址:http://jinyejixie.com/article6/ddoieog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、商城網(wǎng)站、做網(wǎng)站、云服務(wù)器、軟件開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)