The content of this article is about PHP custom sorting, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
html Page
<td class="textcenter"> <input type="text" name="cat[order]" value="{$vo.order}" class="hy_input orders" orderid="{$vo.cat_id}" style="width:50px;" /> </td> js 页面 <script type="text/javascript"> $(".orders").change(function(){ var orderid = $(this).attr('orderid'); var ordernum = $(this).val(); $.post("{:U('Image/listorder')}",{"orderid":orderid,"ordernum":ordernum},function(data){ if(data.code==1000){ location.replace(location); }else{ alert(data.msg); } },"json"); }); </script>
php page:
/** * 排序操作 */ public function listorder(){ if(IS_POST){ $orderid = I("post.orderid",'','intval'); $ordernum = I("post.ordernum",'','intval'); if(empty($orderid)){ $ini=array( 'code'=>222, 'msg'=>'id不合法' ); $this->ajaxReturn($ini); } $listresult = M('Cat')->where("cat_id={$orderid} and status=0")->find(); if(empty($orderid)){ $ini=array( 'code'=>223, 'msg'=>'id已失效' ); $this->ajaxReturn($ini); } $arr =array(); $arr['order'] = $ordernum; $result = M('Cat')->where("cat_id={$orderid}")->save($arr); if($result){ $ini=array( 'code'=>1000, 'msg'=>'操作成功' ); }else{ $ini=array( 'code'=>224, 'msg'=>'操作失败' ); } $this->ajaxReturn($ini); } }
The above is the detailed content of php custom sorting. For more information, please follow other related articles on the PHP Chinese website!