控制器部分代码:
1 if (trim($_GET['keyword']) != '') { 2 //echo $_GET['search_type']; exit(); 3 switch ($_GET['search_type']) { 4 case 0: 5 $where['goods_id'] = array('like', '%' . trim($_GET['keyword']) . '%'); 6 break; 7 case 1: 8 $where['goods_name'] = array('like', '%' . trim($_GET['keyword']) . '%'); 9 break; 10 case 2: 11 $where['goods_serial'] = intval($_GET['keyword']); 12 break; 13 } 14 } 15 $goods_list = $model_goods->where($where)->page(8)->order('goods_addtime DESC')->select();
模板账号:
1 <form method="get" action=""> 2 <input type="hidden" name="act" value="goods_public" /> 3 <input type="hidden" name="op" value="goodsOp" /> 4 <select name="search_type" id=""> 5 <option value="0">商品ID</option> 6 <option value="1">商品名称</option> 7 <option value="2">商品货号</option> 8 </select> 9 <tr> 10 <td></td> 11 <td class="w160"> 12 <input type="text" class="text" name="keyword" value="<?php echo $_GET['keyword']; ?>"/> 13 </td> 14 <td class="tc w70"> 15 <label class="submit-border"> 16 <input type="submit" class="submit" value="搜索" /> 17 </label> 18 </td> 19 </tr> 20 </form>