ThinkPHP 實現新聞後臺資料上移、下移功能
阿新 • • 發佈:2019-01-28
public function moveup(){ //獲取上一條新聞資訊 $m = M('News'); $dataOri = $m->where('orderid='.$_GET['orderid'])->select(); $map['orderid'] = array('lt',$_GET['orderid']); $data = $m->where($map)->order('orderid desc')->limit(1)->select(); //echo count($data); if(count($data)>0){ $newOrderid = $data[0]['orderid']; $data[0]['orderid'] = $_GET['orderid']; $m->save($data[0]); $dataOri[0]['orderid']=$newOrderid; $m->save($dataOri[0]); //跳轉到顯示專案列表頁 $this->redirect('/News/index/p/'.$_GET['p']); }else{ $this->redirect('/News/index/p/'.$_GET['p']); } } public function movedown(){ //獲取下一條新聞資訊 $m = M('News'); $dataOri = $m->where('orderid='.$_GET['orderid'])->select(); $map['orderid'] = array('gt',$_GET['orderid']); $data = $m->where($map)->order('orderid asc')->limit(1)->select(); //echo count($data); if(count($data)>0){ $newOrderid = $data[0]['orderid']; $data[0]['orderid'] = $_GET['orderid']; $m->save($data[0]); $dataOri[0]['orderid']=$newOrderid; $m->save($dataOri[0]); //跳轉到顯示專案列表頁 $this->redirect('/News/index/p/'.$_GET['p']); }else{ $this->redirect('/News/index/p/'.$_GET['p']); } }