-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_search.php
More file actions
138 lines (130 loc) · 3.57 KB
/
Copy pathfilter_search.php
File metadata and controls
138 lines (130 loc) · 3.57 KB
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
<?php
include_once('db_conn.php');
$conn = connect_to_db();
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
$query = 'select * from posts where ';
$nfilter = 0;
if( $_POST['year_min'] != '' ){
$year_min = $_POST['year_min'];
$query = $query.' year > '.$year_min;
$nfilter = $nfilter + 1;
}
if( $_POST['year_max'] != '' ){
$year_max = $_POST['year_max'];
if($nfilter != 0){
$query = $query.' AND';
}
$query = $query.' year < '.$year_max;
$nfilter = $nfilter + 1;
}
if( $_POST['price_min'] != '' ){
$price_min = $_POST['price_min'];
if($nfilter != 0){
$query = $query.' AND';
}
$query = $query.' price > '.$price_min;
$nfilter = $nfilter + 1;
}
if( $_POST['price_max'] != '' ){
$price_max = $_POST['price_max'];
if($nfilter != 0){
$query = $query.' AND';
}
$query = $query.' price < '.$price_max;
$nfilter = $nfilter + 1;
}
if( isset($_POST['city']) ){
error_log("here city", 0);
$city = $_POST['city'];
if($nfilter >0){
$query = $query.' AND (';
} else{
$query = $query.'(';
}
$n = 0;
foreach ($city as $c){
if($n != 0){
$query = $query.' OR';
}
$query = $query.' city = "'.$c.'"';
$n = $n + 1;
}
$nfilter = $nfilter + 1;
$query = $query.')';
}
if( isset($_POST['models']) ){
error_log("here models",0);
$model = $_POST['models'];
if($nfilter >0){
$query = $query.' AND (';
} else{
$query = $query.'(';
}
$n = 0;
foreach ($model as $c){
if($n != 0){
$query = $query.' OR';
}
$query = $query.' model = "'.$c.'"';
$n = $n + 1;
}
$nfilter = $nfilter + 1;
$query = $query.')';
}
if( isset($_POST['makes']) ){
error_log("here makes", 0);
$makes = $_POST['makes'];
if($nfilter >0){
$query = $query.' AND (';
} else{
$query = $query.'(';
}
$n = 0;
error_log(print_r($makes, true), 0);
$cou = count($makes);
error_log($cou,0);
foreach ($makes as $c){
error_log($c,0);
if($n != 0){
$query = $query.' OR';
}
$query = $query.' make = "'.$c.'"';
$n = $n + 1;
}
$nfilter = $nfilter + 1;
$query = $query.')';
}
error_log($query,0);
$result = mysqli_query($conn,$query);
if(!$result) {
echo $conn->error;
die;
}
$return = '<table class="table table-dark table-bordered"';
$return = $return.' '.'<thead><tr>
<th scope="col">Post #</th>
<th scope="col">Make</th>
<th scope="col">Model</th>
<th scope="col">Year</th>
<th scope="col">Price</th>
<th scope="col">Milage</th>
<th scope="col">City</th>
<th scope="col">State</th>
<th scope="col">VIN</th>
</tr></thead>';
foreach($result as $row) {
$return = $return.' '."<tr><td>".$row['post_id']."</td>
<td id='make_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['make']."</td>
<td id='model_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['model']."</td>
<td id='year_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['year']."</td>
<td id='price_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['price']."</td>
<td id='miles_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['mileage']."</td>
<td id='city_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['city']."</td>
<td id='state_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['state']."</td>
<td id='vin_".$row['post_id']."' class='".$row['post_id']." editable'>".$row['VIN']."</td>
<td><button onclick=redir('".$row['post_id']."') class='btn btn-success' type='button'>View</button></td></tr>";
}
$return = $return.' '. "</table>";
echo $return;
?>