日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

thinkphp5 ajax搜索+分页

發布時間:2023/11/29 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 thinkphp5 ajax搜索+分页 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • ? ? ? ? ? ? ? ??<center>??
  • ????????????????<table?>??
  • ??
  • ????????????????????<tr>??
  • ????????????????????????水果名稱<input?type="text"?name="f_name"?class="f_name">??
  • ????????????????????????水果分類??
  • ????????????????????????<select?name="t_id"?id=""?class="t_id">??
  • ????????????????????????????<option?value="">請選擇分類</option>??
  • ????????????????????????????{foreach?name='type'?item='vo'}??
  • ????????????????????????????<option?value="{$vo.t_id}">{$vo.t_name}</option>??
  • ????????????????????????????{/foreach}??
  • ????????????????????????</select>??
  • ??
  • ????????????????????????上架狀態??
  • ????????????????????????<select?name="is_show"??class="is_show">??
  • ????????????????????????????<option?value="">請選擇上架狀態</option>??
  • ????????????????????????????<option?value="1">上架</option>??
  • ????????????????????????????<option?value="0">未上架</option>??
  • ????????????????????????</select>??
  • ???????????????????????活動狀態??
  • ????????????????????????<select?name="is_hot"?class="is_hot">??
  • ????????????????????????????<option?value="">請選擇活動狀態</option>??
  • ????????????????????????????<option?value="1">參與活動</option>??
  • ????????????????????????????<option?value="0">未參與活動</option>??
  • ????????????????????????</select>??
  • ????????????????????????<input?type="button"?value="搜索"?class="sou">??
  • ????????????????????</tr>??
  • ??
  • ????????????????</table>??
  • ????????????????</center>??
  • ????????????????<table?id="sample-table-1"?class="table?table-striped?table-bordered?table-hover">??
  • ????????????????????<thead>??
  • ????????????????????<tr>??
  • ??
  • ????????????????????????<th?class="center">??
  • ????????????????????????????<label>??
  • ????????????????????????????????<input?type="checkbox"?class="ace"?/>??
  • ????????????????????????????????<span?class="lbl"></span>??
  • ????????????????????????????</label>??
  • ????????????????????????</th>??
  • ????????????????????????<th>商品編號</th>??
  • ????????????????????????<th>商品名稱</th>??
  • ????????????????????????<th>商品圖片</th>??
  • ????????????????????????<th>所屬分類</th>??
  • ????????????????????????<th>水果重量</th>??
  • ????????????????????????<th>水果庫存</th>??
  • ????????????????????????<th>已銷售量</th>??
  • ????????????????????????<th>產地</th>??
  • ????????????????????????<th>銷售價</th>??
  • ????????????????????????<th>會員價</th>??
  • ????????????????????????<th>是否上架</th>??
  • ????????????????????????<th>是否參與活動</th>??
  • ????????????????????????<th>操作</th>??
  • ????????????????????</tr>??
  • ????????????????????</thead>??
  • ??
  • ????????????????????<tbody?class="body">??
  • ????????????????????{foreach?name='data'?item='v'}??
  • ????????????????????<tr>??
  • ????????????????????????<td?class="center">??
  • ????????????????????????????<label>??
  • ????????????????????????????????<input?type="checkbox"?class?='box'?name="box"?alt="{$v.f_id}"/>??
  • ????????????????????????????????<span?class="lbl"></span>??
  • ????????????????????????????</label>??
  • ????????????????????????</td>??
  • ??
  • ??
  • ????????????????????????<td>{$v.f_id}</td>??
  • ????????????????????????<td>{$v.f_name}</td>??
  • ????????????????????????<td><img?src="<?php?echo?$v['f_img'];?>"?alt=""?width="50"></td>??
  • ????????????????????????<td>{$v.t_name}</td>??
  • ????????????????????????<td>{$v.f_weight}</td>??
  • ????????????????????????<td>{$v.f_surplus}</td>??
  • ????????????????????????<td>{$v.f_sale}</td>??
  • ????????????????????????<td>{$v.f_place}</td>??
  • ????????????????????????<td>{$v.m_price}</td>??
  • ????????????????????????<td>{$v.v_price}</td>??
  • ????????????????????????<td>??
  • ????????????????????????????{if?condition="$v.is_show?==?1"}??
  • ?????????????????????????????上架??
  • ????????????????????????????{else?/}??
  • ?????????????????????????下架??
  • ????????????????????????????{/if}??
  • ????????????????????????</td>??
  • ????????????????????????<td>??
  • ????????????????????????????{if?condition="$v.is_hot==?1"}??
  • ?????????????????????????????參與活動??
  • ????????????????????????????{else?/}??
  • ?????????????????????????不參與活動??
  • ????????????????????????????{/if}??
  • ????????????????????????</td>??
  • ????????????????????????<td>??
  • ????????????????????????????<a?href="{:url('index/Goods/modify')}?fid={$v.f_id}">編輯</a>??
  • ????????????????????????????<button?class="del"?alt="{$v.f_id}">刪除</button>??
  • ????????????????????????</td>??
  • ??
  • ????????????????????</tr>??
  • ????????????????????{/foreach}??
  • ??
  • ??
  • ??
  • ????????????????????</tbody>??
  • ????????????????</table>??
  • ????????????????<center>??
  • ????????????????<table?>??
  • ????????????????<div><div?class="pages">{$page}</div>??
  • ????????????????????<input?type="button"?class="quan"?value="全選">??
  • ????????????????????<input?type="button"?class="fan"?value="反選">??
  • ????????????????????<input?type="button"?class="pishan"?value="批刪">??
  • ????????????????????<input?type="text"?class="pa"?value="{$num}"></div>??
  • ??
  • ????????????????</table>??
  • ????????????????</center>??
  • ????????????</div><!--?/.table-responsive?-->??
  • ????????</div><!--?/span?-->??
  • ????</div><!--?/row?-->??
  • ????<script?src="js/jq.js"></script>??
  • ????<script>??
  • ????????var?obj=?new?Object();??
  • ????????$('.sou').click(function(){??
  • ????????????obj['f_name']=$('.f_name').val();??
  • ????????????obj['t_id']=$('.t_id').val();??
  • ????????????obj['is_show']=$('.is_show').val();??
  • ????????????obj['is_hot']=$('.is_hot').val();??
  • //????????????alert(obj['t_id']);??
  • ????????????obj['id']=2??
  • ????????????page(1);??
  • ????????})??
  • ????????//分頁??
  • ??
  • ????????function?page(p){??
  • ????????????var?html='';??
  • ????????????$.each(obj,function(k,v){??
  • ????????????????html+=k+'='+v+'&';??
  • ????????????});??
  • ????????????var?num=$('.pa').val();??
  • ????????????var?str='';??
  • ??
  • ????????????$.ajax({??
  • ????????????????type:?"POST",??
  • //????????????????url:?"index.php/index/goods/page",??
  • ????????????????url:?"{:url('index/Goods/page')}",??
  • ????????????????data:?html+"p="+p+"&num="+num,??
  • ????????????????dataType:'json',??
  • ????????????????success:?function(msg){??
  • ??
  • ????????????????????$('.pages').html(msg.page);??
  • ????????????????????$('.pa').val(num);??
  • ????????????????????var?is_show='';??
  • ????????????????????var?is_hot='';??
  • ????????????????????$.each(?msg.list,?function(k,?v){??
  • ????????????????????????if(v.is_show==1){??
  • ????????????????????????????is_show='上架'??
  • ????????????????????????}else?{??
  • ????????????????????????????is_show='下架'??
  • ????????????????????????}??
  • ????????????????????????if(v.is_hot==1){??
  • ????????????????????????????is_hot='參與活動'??
  • ????????????????????????}else?{??
  • ????????????????????????????is_hot='不參與活動'??
  • ????????????????????????}??
  • ????????????????????????str+='<tr><td?class="center"><label><input?type="checkbox"?class?="box"?name="box"?alt="'+?v.f_id+'"/><span?class="lbl"></span></label></td>';??
  • ????????????????????????str+='<td>'+v.f_id+'</td><td>'+v.f_name+'</td><td><img?src="'+?v.f_img+'"?alt=""?width="50"></td><td>'+v.t_name+'</td><td>'+v.f_weight+'</td><td>'+v.f_surplus+'</td><td>'+v.f_sale+'</td><td>'+v.f_place+'</td><td>'+v.m_price+'</td><td>'+v.v_price+'</td>';??
  • ???????????????????????????str+='<td>'+is_show+'</td><td>'+is_hot+'</td><td><a?href="index.php/index/Goods/modify?fid='+v.f_id+'">編輯</a><button?class="del"?alt="'+v.f_id+'">刪除</button></td></tr>';??
  • //????????????????????????str+='<tr><td>'+v.user_id+'</td><td>'+v.username+'</td><td>'+v.sex+'</td><td>'+v.age+'</td><td><'+v.lasttime+'</td></tr>';??
  • ????????????????????});??
  • ????????????????????$('.body').html(str);??
  • ??
  • ????????}??
  • ????????????});??
  • ????????}??
  • ??
  • ??
  • ????
  • [php]?view plaincopy
  • ????public?function?lists()??
  • ????{??
  • //??????商品關聯分類查詢?普通展示??
  • //??????$data?=?db('sg_fruits')??
  • //??????????->join('sg_type',?'sg_fruits.t_id?=?sg_type.t_id')??
  • //??????????->select();??
  • //??????$this->view->engine->layout(true);??
  • //??????$this->assign('data',?$data);??
  • //??????return?view('lists');??
  • //??
  • //??
  • ??
  • ????????//分頁展示??
  • ????????//總條數??
  • ????????$count=db('sg_fruits')??
  • ????????->join('sg_type','sg_fruits.t_id?=?sg_type.t_id')??
  • ????????????->count();??
  • ????????//默認當前頁1//每頁顯示條數??
  • ????????$p=1;$num=5;??
  • ????????$limit=($p-1)*$num;??
  • ??
  • ????????$fruits=new?Fruits();??
  • ????????$page=$fruits->fen($count,$p,$num);??
  • ????????$data=db('sg_fruits')??
  • ????????????->join('sg_type','sg_fruits.t_id?=?sg_type.t_id')??
  • ????????????->limit($limit,$num)??
  • ????????????->select();??
  • ????????//查詢分類??
  • ????????$type=?db('sg_type')->select();??
  • ??
  • ????????//?把分頁數據賦值給模板變量list??
  • ????????$this->view->engine->layout(true);??
  • ??
  • ????????$this->assign('data',?$data);??
  • ????????$this->assign('page',?$page);??
  • ????????$this->assign('type',?$type);??
  • ????????$this->assign('num',?$num);??
  • ??
  • ????????//?渲染模板輸出??
  • ???????return?$this->fetch();??
  • ??
  • ????}??
  • //分頁2往后??
  • ????public?function??page(){??
  • ????????if(isset($_POST['id'])){??
  • ????????????$arr=$_POST;??
  • //??????????var_dump($arr);die;??
  • ????????????$where[]='1=1';??
  • ????????????if(!empty($arr['is_hot??'])){??
  • ????????????????$a?=?$arr['is_hot'];??
  • ????????????????$where[]=?'is_hot?='."$a";??
  • ????????????}??
  • ????????????if(!empty($arr['is_show']))?{??
  • ????????????????$b?=?$arr['is_show'];??
  • ????????????????$where[]?=?'is_show?='?.?"$b";??
  • ????????????}??
  • ????????????if(!empty($arr['t_id']))?{??
  • ????????????????$d?=?$arr['t_id'];??
  • ????????????????$where[]?=?'sg_fruits.t_id?='."$d";??
  • ????????????}??
  • ????????????if(!empty($arr['f_name']))?{??
  • ????????????????$c?=?$arr['f_name'];??
  • ????????????????$where[]?=?'f_name??like?\'%'?.?"$c".'%\'';??
  • ????????????}??
  • ??
  • ????????????$wh=implode('?AND?',$where);??
  • //??????????echo?$wh;die;??
  • ??????????????
  • ????????????$num=$_POST['num'];??
  • ????????????$p=$_POST['p'];??
  • ????????????$fruits=new?Fruits();??
  • ????????????//總條數??
  • ????????????$count=db('sg_fruits')??
  • ????????????????->join('sg_type','sg_fruits.t_id?=?sg_type.t_id')??
  • ????????????????->where($wh)??
  • ????????????????->count();??
  • ????????????$data['page']=$fruits->fen($count,$p,$num);??
  • ????????????$limit=($p-1)*$num;??
  • ????????????$data['list']=db('sg_fruits')??
  • ????????????????->join('sg_type','sg_fruits.t_id?=?sg_type.t_id')??
  • ????????????????->where($wh)??
  • ????????????????->limit($limit,$num)??
  • ????????????????->select();??
  • ????????????echo?json_encode($data);??
  • ????????}else{??
  • ????????????$num=$_POST['num'];??
  • ????????????$p=$_POST['p'];??
  • ????????????$fruits=new?Fruits();??
  • ????????????//總條數??
  • ????????????$count=db('sg_fruits')??
  • ????????????????->join('sg_type','sg_fruits.t_id?=?sg_type.t_id')??
  • ????????????????->count();??
  • ????????????$data['page']=$fruits->fen($count,$p,$num);??
  • ????????????$limit=($p-1)*$num;??
  • ????????????$data['list']=db('sg_fruits')??
  • ????????????????->join('sg_type','sg_fruits.t_id?=?sg_type.t_id')??
  • ????????????????->limit($limit,$num)??
  • ????????????????->select();??
  • ????????????echo?json_encode($data);??
  • ????????}??
  • ?

    [php]?view plaincopy
  • <?php??
  • namespace?app\index\model;??
  • ??
  • use?think\Model;??
  • ??
  • class?Fruits{??
  • ?????public?function?fen($count,$p,$num)??
  • ????{??
  • ????????//分頁數據??
  • ????????$pageSum=ceil($count/$num);//總頁數??
  • ????????$prevPage=$p-1>1?$p-1:1;//上一頁??
  • ????????$nextPage=$p+1<$pageSum?$p+1:$pageSum;//下一頁;??
  • ????????$str='';??
  • ????????$str.='<a?href="javascript:page(1)">首頁</a>';??
  • ????????$str.='<a?href="javascript:page('.$prevPage.')">上一頁</a>';??
  • ????????$str.=$p.'/'.$pageSum;??
  • ????????$str.='<a?href="javascript:page('.$nextPage.')">下一頁</a>';??
  • ????????$str.='<a?href="javascript:page('.$pageSum.')">末頁</a>';??
  • ????????return?$str;??
  • ??
  • ????}??
  • }??
  • ??
  • ??
  • ??
  • ?>??

  • </script>

    轉載于:https://www.cnblogs.com/phpzlq/p/9154278.html

    總結

    以上是生活随笔為你收集整理的thinkphp5 ajax搜索+分页的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。