Search data between two dates in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jatinbedi
    New Member
    • Dec 2015
    • 1

    Search data between two dates in php

    HTML PART

    Code:
    <tr>
        <td><form id="form1" name="form1" method="post" action="list-date.php">
          <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
            <tr>
              <td width="88" class="small_font"><strong> First Date</strong></td>
              <td width="184"><label for="date1"></label>
                <input name="date1" type="text" id="date1" style="width:150px" readonly="readonly" onclick="javascript:NewCal('date1','YYYYMMDD')" />
                <a href="javascript:NewCal('date1','YYYYMMDD')"><img src="https://bytes.com/topic/includes/datetime/cal.gif" alt="+" width="16" height="16" border="0" /></a></td>
              <td width="100" class="small_font"><strong> Second Date</strong></td>
              <td width="185"><input name="date2" type="text" id="date2" style="width:150px" readonly="readonly" onclick="javascript:NewCal('date2','YYYYMMDD')" />
                <a href="javascript:NewCal('date2','YYYYMMDD')"><img src="https://bytes.com/topic/includes/datetime/cal.gif" alt="+" width="16" height="16" border="0" /></a></td>
              <td width="83"><input type="submit" name="button" id="button" value="Search" /></td>
            </tr>
          </table>
        </form></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td width="60" class="td">USER ID</td>
            <td width="100" class="td">User Name</td>
            <td width="120" class="td">Sponsor</td>
            <td width="92" class="td">Phone No</td>
             <td width="185" class="td">Action</td>
          </tr>
             <?php echo $msg;?>  
    
    PHP  Part
    
    <?php 
    	include_once("../../init.php");
    	validation_check($_SESSION['UID'], SITE_HOME_ADMIN);
    	$msg='';
    	if(isset($_POST['button'])){
      
         $date1 = $_POST["date1"];  
         $date2 = $_POST["date2"];  
         $timestampdate1 = strtotime($date1);  
         $timestampdate2 = strtotime($date2);  
      
    	
    
    	
    	$qr = mysql_query("SELECT * FROM user WHERE join_date BETWEEN '$date1' AND  '$date2'
    ORDER by id DESC") or die('Error in connection');
    	while($rs = mysql_fetch_array($qr))
    	{
    		 $msg .='<tr>
    			<td>'.$rs['user'].'</td>
    			<td>'.$rs['fname'].'</td>
    			<td>'.$rs['sponsor'].'</td>
    			<td>'.$rs['phone'].'</td>
    			<td><a href="user-edit.php?c='.$rs['user'].'">EDIT</a> | <a href="user-del.php?b='.$rs['user'].'">Block</a> | <a href="user-del.php?a='.$rs['user'].'">ALLOW</a> </td>
    		  </tr>';	}
    		}	
    ?>
    Last edited by Rabbit; Dec 17 '15, 05:17 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    so, what’s the problem?

    also note:
    - join_date should be a DATE type and not an INTEGER column

    Comment

    Working...