PHP+Ajax实现后台文章快速排序
PHP+Ajax实现后台文章快速排序
在后台我们经常遇到文章排序功能,今天我们就在表格里面加个排序字段,实现实时排序功能。
也就是文章按照由小到大的顺序排序。
文章列表
<tablewidth="100%"cellspacing="0"cellpadding="0"border="0"><tbody><tr><td>用户名</td><td>内容</td><tdwidth="120px">排序</td></tr><?php$sql="SELECTname,content,id,ordFROMwishing_wallORDERBYordASClimit0,10";$query=mysql_query($sql);while($row=mysql_fetch_array($query)){?><tr><td><ahref='http://www.sucaihuo.com/php/389.html'target='_blank'><?phpecho$row['name'];?></td><td><?phpecho$row['content'];?></td><td><aonclick="changeOrd($(this),'<?phpecho$row['id'];?>')"><?phpecho$row['ord'];?></a></td></tr><?php}?></tbody></table>
点击排序出现输入框,和确认方法
functionchangeOrd(obj,id){varval=obj.text();varc=obj.parent("td");obj.parent("td").html("<inputtype='text'style='width:50px;'onFocus=this.select()onblur=changeOrdConfirm($(this),"+id+")value='"+val+"'/>");c.children("input").focus();}functionchangeOrdConfirm(obj,id){varord=obj.val();$.post("ajax.php",{id:id,ord:ord},function(data){obj.parent("td").html("<aonclick=changeOrd($(this),"+id+")>"+obj.val()+"</a>");})}
ajax远程操作排序字段
include_once("connect.php");$id=isset($_POST['id'])?intval($_POST['id']):0;$ord=isset($_POST['ord'])?intval($_POST['ord']):0;if($id>0){$sql="UPDATE`wishing_wall`SET`ord`='".$ord."'WHERE`id`='".$id."';";mysql_query($sql);}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。