-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmycode.to.dev.txt
157 lines (111 loc) · 3.45 KB
/
mycode.to.dev.txt
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
>>>> PHP Code To Dev <<<<<
--------------------------------------------------------------
--------------------------------------------------------------
Key: Search Data Between Two Dates In PHP,
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
--------------------------------------------------------------
//Search Data Between Two Dates In PHP
//Download jqery datepicker from jquery.com
//Code Is Working.
<!-- PHP Search date between two dates -->
<?php
$sub_qry="";
if(isset($_POST['submit'])) {
$from=$_POST['from'];
$fromArr=explode("/", $from);
$from=$fromArr[2]."-".$fromArr[0]."-".$fromArr[1];
$from=$from." 00:00:00";
$to=$_POST['to'];
$toArr=explode("/", $to);
$to=$toArr[2]."-".$toArr[0]."-".$toArr[1];
$to=$to." 23:59:59";
echo $from;
$sub_qry = " where created_at >= '$from' && created_at <= '$to'";
$con = new mysqli("localhost","root","","yii2");
$result = $con->query("select name,price from products $sub_qry order by id desc");
$serchedData = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$serchedData[] = $row;
//echo "<pre>";print_r($serchedData);
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
</head>
<body>
<!-- Select From and To Dates -->
<h1>Fetch Data Between Two Dates: FromDate & ToDate</h1>
<form action="" method="POST">
<label for="from">From</label>
<input type="text" id="from" name="from" required="required">
<label for="to">to</label>
<input type="text" id="to" name="to" required="required">
<input type="submit" name="submit" value="Filter">
</form>
<table border=2>
<thead>
<tr>
<th>Name</th><th>Price</th>
</tr>
</thead>
<tbody>
<?php
if(isset($serchedData) && $serchedData !== '') {
foreach($serchedData as $us) {
echo "<tr>";
echo "<td>".$us['name']."</td>";
echo "<td>"."$".$us['price']."</td>";
echo "</tr>";
}
}?>
</tbody>
</table>
</body>
</html>
<script>
$( function() {
var dateFormat = "mm/dd/yy",
from = $( "#from" )
.datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function() {
to.datepicker( "option", "minDate", getDate( this ) );
}),
to = $( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
} );
</script>
<---------- Fetch Date between two dates -------------------->
----------------------------------------------------------------
----------------------------------------------------------------