Home  >  Article  >  php教程  >  PHP实现快速排序效果

PHP实现快速排序效果

WBOY
WBOYOriginal
2016-06-07 11:37:361110browse

在后台我们经常遇到文章排序功能,今天我们就在表格里面加个排序字段,实现实时排序功能。
也就是文章按照由小到大的顺序排序。
PHP实现快速排序效果
文章列表<table> <br>     <tbody> <br>         <tr> <br>             <td>用户名</td> <br>             <td>内容</td> <br>             <td>排序</td> <br>         </tr> <br>         <?php <br />         $sql = "SELECT name,content,id,ord FROM wishing_wall ORDER BY ord ASC limit 0,10 "; <br>         $query = mysql_query($sql); <br>         while ($row = mysql_fetch_array($query)) { <br>             ?> <br>  <br>             <tr> <br>                 <td><?php echo $row[&#039;name&#039;]; ?></td> <br>                 <td><?php echo $row[&#039;content&#039;]; ?></td> <br>                 <td><a>')"><?php echo $row[&#039;ord&#039;]; ?></a></td> <br>             </tr>    <br>         <?php } ?> <br>     </tbody> <br> </table>点击排序出现输入框,和确认方法function changeOrd(obj, id) { <br>     var val = obj.text(); <br>     var c = obj.parent("td"); <br>     obj.parent("td").html("<input>"); <br>     c.children("input").focus(); <br> } <br> function changeOrdConfirm(obj, id) { <br>     var ord = obj.val(); <br>     $.post("ajax.php", { <br>         id: id, <br>         ord: ord <br>     }, <br>     function(data) { <br>         obj.parent("td").html("<a>" + obj.val() + "</a>"); <br>     }) <br> }ajax远程操作排序顺序include_once("connect.php"); <br>  <br> $id = isset($_POST['id']) ? intval($_POST['id']) : 0; <br> $ord = isset($_POST['ord']) ? intval($_POST['ord']) : 0; <br> if ($id > 0) { <br>     $sql = "UPDATE `wishing_wall` SET `ord` = '".$ord."' WHERE `id` = '" . $id . "';"; <br>      mysql_query($sql); <br> }php排序演示:http://www.sucaihuo.com/php/389.html

附件 jQuery+Ajax实现排序效果.rar ( 8.93 KB 下载:21 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn