PHP MYSQL Date Range Search with Jquery Datepicker -


i've tried few different solutions problem can't seem find 1 works. trying search date range datetime field in mysql database. here's jquery before form:

  <script type="text/javascript" language="javascript">             jquery(function() {                 jquery( "#from" ).datepicker({                   defaultdate: "+1w",                   changemonth: true,                   numberofmonths: 1,                   dateformat: "yy-mm-dd",                   onclose: function( selecteddate ) {                     $( "#to" ).datepicker( "option", "mindate", selecteddate );                   }                 });                 jquery( "#to" ).datepicker({                   defaultdate: "+1w",                   changemonth: true,                   numberofmonths: 1,                   dateformat: "yy-mm-dd",                   onclose: function( selecteddate ) {                     jquery( "#from" ).datepicker( "option", "maxdate", selecteddate );                   }                 });             }); </script> 

heres simple form:

<form method="post" action="search.php"> <p>select date range: </p><label style="color:#fff;" for="from">from</label> from:<input type="text" id="from" name="from" /> <label style="color:#fff;" for="to" >to</label> to:<input type="text" id="to" name="to" /> <input name="export" type="submit" value="search" /> </form> 

and here's sql statement:

        $hostname = ""; //set server/hostname     $dbusername = ""; //set database username     $dbname = ""; //set database name     $dbpassword = ""; //set database username     $link = mysqli_connect($hostname, $dbusername, $dbpassword, $dbname);      if (!$link) {      die('connect error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());      }  $sql = "select * log call_date >= date_format('" . $from . "', '%y%m%d') , call_date <=  date_format('" . $to . "', '%y%m%d')"; //$sql = "select * log call_date >= '".date("y-m-d", strtotime($from))."' , call_date <=  '".date("y-m-d", strtotime($to))."'";    //$sql = "select * log call_date >= '$from' , call_date <=  '$to'";      $result = mysqli_query($link, $sql, mysqli_store_result); while($row = $result->fetch_assoc()){         $name= $row['name'];         $disposition = $row['did_id'];         $date = $row['call_date']; } 

...then outputting results. can see tried few different sql statements i've commented out. know can connect database, know getting dates in format yyyy-mm-dd, , datetime field has format yyyy-mm-dd hh:mm:ss. appreciated. thank you.

change

   $sql = "select * log call_date >= date_format('" . $from . "', '%y%m%d') , call_date <=  date_format('" . $to . "', '%y%m%d')"; 

to

   $sql = "select * log call_date >= date_format('" . $from . "', '%y/%m/%d') , call_date <=  date_format('" . $to . "', '%y/%m/%d')";  

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -