I want to use the datepicker to query the data between two days.

I want to use the datepicker to query the data between two days.

I want to use the datepicker to query the data from MySQL database.

I add the 00:00:00 and 23:59:59 because my data type is timestamp ,but the code can't work.

Please help me !

This is my code.

test_jquery2.php
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="utf-8">
  5.   <title>Computer Facilities Temperature & Humidity Log</title>
  6.     <style type="text/css">
  7.         .table_titles, .table_cells_odd, .table_cells_even {
  8.                 padding-right: 20px;
  9.                 padding-left: 20px;
  10.                 color: #000;
  11.         }
  12.         .table_titles {
  13.             color: #FFF;
  14.             background-color: #666;
  15.         }
  16.         .table_cells_odd {
  17.             background-color: #CCC;
  18.         }
  19.         .table_cells_even {
  20.             background-color: #FAFAFA;
  21.         }
  22.         table {
  23.             border: 2px solid #333;
  24.         }
  25.         body { font-family: "Trebuchet MS", Arial; }
  26.     </style>
  27.   <link rel="stylesheet" href="jquery-ui.css">
  28.   <script src="jquery-1.11.2.js"></script>
  29.   <script src="jquery-ui.js"></script>
  30.   <link rel="stylesheet" href="/resources/demos/style.css">
  31.   <script>
  32.   $(function() {
  33.     $( "#sdatepicker" ).datepicker({
  34. dateFormat: "yy-mm-dd",
  35. constrainInput: false
  36. });
  37.  $( "#edatepicker" ).datepicker({
  38. dateFormat: "yy-mm-dd",
  39. constrainInput: false
  40. });
  41.   });
  42.   
  43.   $(document).ready(function(){
  44.   $("#generate_log").click(function(){
  45.  var sdatepicker=jQuery("#sdatepicker").val() +" 00:00:00";
  46.  var edatepicker=jQuery("#edatepicker").val() +" 23:59:59";

  47.  
  48.  var data =
  49.  {
  50.   sdatepicker:sdatepicker ,
  51. edatepicker:edatepicker
  52. }
  53. jQuery.ajax({
  54. type: "POST",
  55. url: "test.php",
  56. data: data,
  57. success: function(response){
  58.  }
  59. });
  60.   });
  61. });
  62.   
  63.   
  64.   
  65.   </script>
  66. </head>
  67. <body>

  68. <h1>Computer Facilities Temperature & Humidity Log</h1>

  69. Start Date: <input type="text" id="sdatepicker">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  70. End Date: <input type="text" id="edatepicker">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  71. <input type="button" name="generate_log" id="generate_log" value="Generate Log" />
  72.  

  73.  
  74. </body>
  75. </html>

test.php
  1. <?php 
  2.     // Start MySQL Connection
  3.     include('dbconnect.php'); 
  4. ?>

  5. <html>
  6. <head>
  7.     
  8.     <style type="text/css">
  9.         .table_titles, .table_cells_odd, .table_cells_even {
  10.                 padding-right: 20px;
  11.                 padding-left: 20px;
  12.                 color: #000;
  13.         }
  14.         .table_titles {
  15.             color: #FFF;
  16.             background-color: #666;
  17.         }
  18.         .table_cells_odd {
  19.             background-color: #CCC;
  20.         }
  21.         .table_cells_even {
  22.             background-color: #FAFAFA;
  23.         }
  24.         table {
  25.             border: 2px solid #333;
  26.         }
  27.         body { font-family: "Trebuchet MS", Arial; }
  28.     </style>
  29. </head>
  30.     <table border="0" cellspacing="0" cellpadding="4">
  31.       <tr>
  32.             <td class="table_titles">ID</td>
  33.             <td class="table_titles">Date and Time</td>
  34.             <td class="table_titles">Temperature</td>
  35.             <td class="table_titles">Humidity</td>
  36.           </tr>
  37. <?php
  38.     // Retrieve all records and display them
  39. error_reporting(0);
  40.     $result = mysql_query("SELECT * FROM thdata WHERE event BETWEEN '".$sdatepicker."' AND '".$edatepicker."' ORDER BY id ASC");

  41.     // Used for row color toggle
  42.     $oddrow = true;

  43.     // process every record
  44.     while( $row = mysql_fetch_array($result) )
  45.     {
  46.         if ($oddrow) 
  47.         { 
  48.             $css_class=' class="table_cells_odd"'; 
  49.         }
  50.         else
  51.         { 
  52.             $css_class=' class="table_cells_even"'; 
  53.         }

  54.         $oddrow = !$oddrow;

  55.         echo '<tr>';
  56.         echo '   <td'.$css_class.'>'.$row["id"].'</td>';
  57.         echo '   <td'.$css_class.'>'.$row["event"].'</td>';
  58.         echo '   <td'.$css_class.'>'.$row["celsius"].'</td>';
  59.         echo '   <td'.$css_class.'>'.$row["humidity"].'</td>';
  60.         echo '</tr>';
  61.     }
  62. ?>
  63.     </table>
  64.     </body>
  65. </html>