tp 多条件查询 及 多表left join查询

tp 多条件查询 及 多表left join查询_第1张图片

控制层

//产品管理列表,同时根据查询条件显示列表
		public function productlist(){
			import('ORG.Util.Page');

            $user_name = trim($_GET['user_name']);
            $phone = trim($_GET['phone']);
            $card_examine = trim($_GET['card_examine']);
            $idcard_examine = trim($_GET['idcard_examine']);
            $starttime = trim($_GET['starttime']);
            $endtime = trim($_GET['endtime']);
            $city = trim($_GET['city']);
            $orga_name = trim($_GET['orga_name']);

			$product   =   M('product');
		
			$count = $product->count();// 查询满足要求的总记录数 
            $Page  = new Page($count,15);// 实例化分页类 传入总记录数
            $show  = $Page->show();// 分页显示输出

            $sql="SELECT `app_product`.id, `app_product`.product_name, `app_product`.product_orga,`app_product`.city,
                `app_product`.create_time,`app_user`.user_name
                  FROM `app_product` LEFT JOIN `app_user`  on `app_product`.userid = `app_user`.id ";
            // var_dump($sql);
            // die();
            $sql=$sql." where 1=1";
            if($user_name){
                $sql = $sql." and user_name like "." '%$user_name%'";
            }
            if($phone){
                $sql = $sql." and phone="."'$phone'";
            }
            if($card_examine == '0' or $card_examine){
                $sql = $sql." and card_examine=".$card_examine;
            }
            if($idcard_examine == '0' or $idcard_examine){
                $sql = $sql." and idcard_examine=".$idcard_examine;
            }
            if($starttime){
                $sql = $sql." and create_time >"." '$starttime' ";
            }
            if($endtime){
                $sql = $sql." and create_time <"." '$endtime' ";
            }
            if($city){
                $sql = $sql." and app_product.city="." '$city' ";
            }
            if($orga_name){
                $sql = $sql." and orga_name like"." '%$orga_name%' ";
            }

            $sql=$sql." ORDER BY app_product.id desc LIMIT $Page->firstRow,$Page->listRows";
            $list = $product ->query($sql);

            // 进行分页数据查询
            //$list = $user->order('id')->limit($Page->firstRow.','.$Page->listRows)->select();
             
            //var_dump($Page->getNowPage());  //得到当前页

            $this->assign('NowPage',$Page->getNowPage());// 赋值数据集
            $this->assign('list',$list);// 赋值数据集
            $this->assign('page',$show);// 赋值分页输出

			$this->display();
		}


显示层

    <html>
     <head>
       <title>hello {$name}</title>
	   <script src="__PUBLIC__/ui/My97DatePicker/WdatePicker.js" ></script>
     </head>
     <body>
		<br><br>
		<form action="__URL__/productlist" method="get" >
			用户姓名<input type="text" name="user_name" />  用户手机<input type="text" name="phone" /> 
			名片认证
			  <select id="u379_input" name="card_examine">
                <option value="1">已认证</option>
                <option value="0">未认证</option>
                <option value="2">审核中</option>
                <option selected="" value="">不限</option>
              </select>
			  
			实名认证
			  <select id="u379_input" name="idcard_examine">
                <option value="1">已认证</option>
                <option value="0">未认证</option>
                <option value="2">审核中</option>
                <option selected="" value="">不限</option>
              </select>
			<br>

			日期<input type="text" name="starttime" id="wdate" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{$data.time}" />——<input type="text" name="endtime" id="wdate" class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="{$data.time}" />  
			城市
			<select id="sel" onChange="chg()" name="city">
				<option value="">请选择</option>
				<option value="北京">北京</option>
				<option value="天津">天津</option>
				<option value="上海">上海</option>
				<option value="重庆">重庆</option>
				<option value="河北">河北</option>
				<option value="山西">山西</option>
				<option value="内蒙古">内蒙古</option>
				<option value="辽宁">辽宁</option>
				<option value="黑龙江">黑龙江</option>
				<option value="江苏">江苏</option>
				<option value="浙江">浙江</option>
				<option value="安徽">安徽</option>
				<option value="福建">福建</option>
				<option value="江西">江西</option>
				<option value="山东">山东</option>
				<option value="河南">河南</option>
				<option value="湖北">湖北</option>
				<option value="湖南">湖南</option>
				<option value="广东">广东</option>
				<option value="广西">广西</option>
				<option value="海南">海南</option>
				<option value="四川">四川</option>
				<option value="贵州">贵州</option>
				<option value="云南">云南</option>
				<option value="西藏">西藏</option>
				<option value="陕西">陕西</option>
				<option value="甘肃">甘肃</option>
				<option value="青海">青海</option>
				<option value="宁夏">宁夏</option>
				<option value="新疆">新疆</option>
				<option value="香港">香港</option>
				<option value="澳门">澳门</option>
				<option value="台湾省">台湾省</option>				
			</select>
			
			机构名称<input type="text" name="orga_name" /><br><br>
					<!--<a href="__URL__/search">搜索</a>-->
			<input type="submit" value="搜索" />
		
		</form>

        <form action="__URL__/deleUser" method="post" name="form1" onsubmit="return anyChecked()" >
		
			
			<br><br>
            产品资源管理 
	        <hr>
                <table cellpadding=3 cellspacing=5>
                    <tr>
                        <td width="10" align="center">ID</td>
                        <td width="80" align="center">产品名</td>
                        <td width="80" align="center">发布时间</td>
                        <td width="80" align="center">浏览次数</td>
                        <td width="120" align="center">产品服务城市</td>	
						<td width="80" align="center">机构</td>
						<td width="80" align="center">用户名</td>
                        <td width="80" align="center"> 操作 </td>             
                    </tr>
                    
                    <!--{$k+($page-1)*5}-->
					<?php //var_dump($list);?>
                    <volist name="list" id="vo" key="k">
                    
                        <tr>
                        <td >

                            <td><input name="checkarrid[]" type="checkbox" value="{$vo.id}" />{$k+($NowPage-1)*15}</td>
                            
                            <td>{$vo.product_name}</td>
							<td>{$vo.create_time}</td>
							<td>{$vo.city}</td>
							<td>{$vo.product_orga}</td>
							
							<td>{$vo.user_name}</td>
							
							<td><a href="<?php echo __URL__;?>/viewproduct?id={$vo.id}">详情</a></td>
                            <td><a href="<?php echo __URL__;?>/deleproduct?id={$vo.id}">删除</a></td>
                            
                            
                           
                            <!--{$vo.pic}
                            [ {$vo.create_time} ] {$vo.title} </td>
                            -->    
                        </tr>
                        <?php $n = $n+1;?>
                    </volist>
                    <tr></tr>
                </table>
                <hr>
				
                <div class="result page">{$page}</div>

                全选:<INPUT id=checkAll onclick=checkall() type=checkbox>   
                <input type="submit" value="删除"/>
        </form>


     </body>
<!-- <a href="<?php echo __URL__;?>/dele">删除</a>   <a href="<?php echo __URL__;?>/dele" onclick=checkall()>全选</a>-->
     <SCRIPT language=javaScript>     
   
//全选或全部不选     
function checkall() {     
    var isChecked=(document.form1.checkAll.checked == true);     
    var elements_all=document.form1.elements;     
    for(i=0;i<elements_all.length;i++) {     
        var element=elements_all[i];     
        if(element.type=="checkbox")  {     
            element.checked=isChecked;     
        }     
    }     
}     
   
//是否有checkbox被选中     
function anyChecked() {     
    var elements_any=document.form1.elements;     
    for(i=0;i<elements_any.length;i++) {     
        var element=elements_any[i];     
        if(element.checked == true) {     
            return true;     
        }     
    }     
    return false;     
}     
   
</SCRIPT>   
    </html>


你可能感兴趣的:(tp 多条件查询 及 多表left join查询)