• PHP+MySQL按时间段查询记录代码


    代码如下:

    <?php
    
    //搜索
    $StarLevel = $_GET["starlevel"];
    
    $StartDate=$_GET["StartDate"];
    
    $EndDate=$_GET["EndDate"];
    
    $Key = $_GET["k"]; 
    
    if($_GET["page"] == ""){
    	$Page = 1;
    } else {
    	$Page = $_GET["page"];
    }
    
    
    $querySel="select *,ho.ID as hoID,ro.ID as roID from roomsy rsy left join room ro on rsy.RoomID=ro.ID left join hotel ho on rsy.HotelID=ho.ID where to_days(EndDate)-to_days(now())>=0";
    
    
    if($StartDate) $querySel = $querySel .  " and to_days(EndDate)-to_days('".$StartDate."')>=0";
    
    if($EndDate) $querySel = $querySel . " and to_days(EndDate)-to_days('".$EndDate."')<=0";
    
    if($StarLevel) $querySel = $querySel . " and StarLevel = '". $StarLevel ."'";
    
    if($Key) $querySel = $querySel . " and ro.RName like '%". $Key ."%'";
    
    $querySel = $querySel . " order by SOrder,rsy.ID desc"; 
    
    $result = mysql_query($querySel) or die(mysql_error()); 
    $total_records = mysql_num_rows($result);   //取得总记录数
    
    $page_size = 12;  //每页显示的条数
    $nums = $total_records;  //总条目数
    $sub_pages = 5;   //每次显示的页数
    $pageCurrent = $_GET["page"];     //得到当前是第几页    
    
    if(!$pageCurrent) $pageCurrent = 1;
    
    //$begin_record = 0;   //显示记录的首行序号
    $begin_record = ($pageCurrent - 1) * $page_size;
    
    if($total_records> 0) 
    { 
    
    	//利用LIMIT关键字获取本页所要显示的记录,注意limit两边要"空格"; 
    	$querySel = $querySel. " limit ".$begin_record. ", ".$page_size; 
    	
    	$result = mysql_query($querySel)   or   die(mysql_error()); 
    	$current_records = mysql_num_rows($result); //取得本页的记录总数 
    	
    	//将查询结果放在$result_show 数组
    	$result_show = array(); 
    
    }
    
    ?>
    

      

  • 相关阅读:
    SGU 107
    HDU 1724 自适应辛普森法
    POJ 1061 扩展欧几里得
    zzuli2424: 越靠近,越幸运(dfs)
    zzuli1519: 小P参加相亲大会(异或)
    zzuli1519: 小P参加相亲大会(异或)
    牛客练习赛42 A:字符串
    牛客练习赛42 A:字符串
    zzuli1511: 小P的loI
    zzuli1511: 小P的loI
  • 原文地址:https://www.cnblogs.com/shanmao/p/3497694.html
Copyright © 2020-2023  润新知