PHP+MySqli EP.9 ระบบค้นหาข้อมูลแบบเลือกช่วงวันที่
PHP+MySqli EP.9 ระบบค้นหาข้อมูลแบบเลือกวันที่
เป็นการค้นหาและเรียกข้อมูลจาก Database มาแสดง
ตัวอย่างไฟล์ และ Database
ตัวอย่าง โค๊ด
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
<?php include ('condb.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="bt/css/bootstrap.min.css" rel="stylesheet"> <link href="bt/css/style.css" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css"> <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script type="text/javascript" src="//cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"> </script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <script src="https://unpkg.com/gijgo@1.9.13/js/gijgo.min.js" type="text/javascript"></script> <link href="https://unpkg.com/gijgo@1.9.13/css/gijgo.min.css" rel="stylesheet" type="text/css" /> <script> $(document).ready(function() { $('#example').DataTable( { "aaSorting" :[[0,'ASC']], }); } ); </script> <title>my backend</title> <style type="text/css"> img { width: 20px; height: auto; } </style> </head> <body> <br> <br> <br> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="panel panel-primary"> <div class="panel-heading"><b><font size="5"><center> ค้นหา ตามช่วงวันที่</center></font></b></div> <div class="panel-body"> <form id="form1" name="form1" class="form-inline" method="post" action="s_date.php"> <center> <div class="form-group"> <label for="exampleInputName2">วันที่ :</label> <input name="d_s" id="datepicker" width="270" /> </div> <div class="form-group"> <label for="exampleInputEmail2"> ถึงวันที่ : </label> <input name="d_e" id="datepicker2" width="270" /> </div> <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> ค้นหา</button></center> </form> </div> </div> </div> </div> </div> <script> $('#datepicker').datepicker({ uiLibrary: 'bootstrap', format: "yyyy-mm-dd", type : "date" }); </script> <script> $('#datepicker2').datepicker({ uiLibrary: 'bootstrap', format: "yyyy-mm-dd", type : "date" }); </script> </div> </div> <div class="container"> <table border="0" align="center" cellspacing="1" class="display" id="example"> <!--ส่วนหัว--> <thead> <tr> <th align="center">ลำดับ</th> <th align="center">วันที่</th> <th align="center">เวลา</th> <th align="center">ip</th> <th align="center">browser</th> <th align="center">os</th> <th align="center">วันที่และเวลา</th> </tr> </thead> <?php $num = 1; $d_s = $_POST['d_s'];//ตัวแปรวันที่เริ่มต้น $d_e = $_POST['d_e'];//ตัวแปรวันที่สิ้นสุด $d_s = $d_s." ".'00.00.00';//กำหนดเวลาเริ่มต้น $d_e= $d_e." ".'23.59.59';//กำหนดเวลาสิ้นสุด echo $d_s; echo "<br>"; echo $d_e; echo "<br>"; $query = "SELECT * FROM wp_statpress where timestamp BETWEEN '$d_s' AND '$d_e' ORDER BY id ASC " or die("Error:" . mysqli_error()); //ประกาศตัวแปร sqli $result = mysqli_query($condb, $query);//ดูชื่อ ตัวแปรในไฟล์ connect ให้ดีว่า conหรือ condb หรืออย่างอื่น $num2 = mysqli_num_rows($result); echo $num2; //สร้างตัวแปร $row มารับค่าจากการ fetch array //วนลูป while($row = mysqli_fetch_array($result)) { ?> <tr> <td><?php echo $num++; ?> </td> <td><?php echo $row['date']; ?></td> <td><?php echo $row['time']; ?></td> <td><?php echo $row['ip']; ?></td> <td><?php echo $row['browser']; ?></td> <td><?php echo $row['os']; ?></td> <td><?php echo $row['timestamp']; ?></td> </tr> <?php } mysqli_close($condb);//ดูชื่อ ตัวแปรในไฟล์ connect ให้ดีว่า conหรือ condb หรืออย่างอื่น ?> </table> </div> </body> </html> |