-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
237 lines (181 loc) · 9.9 KB
/
index.php
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html>
<head>
</head>
<style>
input[type=text] {
width: 50%;
padding: 12px 20px;
margin: 8px 0px;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 50%;
background-color: #012e5e;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
div {
width: 50%;
border-radius: 5px;
background-color: #44b606;
padding: 20px;
border: 1px solid #ccc;
}
</style>
<body>
<form action="vuvedi.php">
<input type="submit" style="width:15%" value="Въведете автомобил" />
</form>
<center>
<h1>Търси автомобил</h1>
<div>
<form action=# method="POST">
Марка:
<select id="marka" name="marka" onchange="change()" style="margin:10px 0px" ><br>
<option >--изберете--</option><br>
<?php
include "config.php";
$result =mysqli_query($dbConn, "SELECT id_marka,marka FROM marka");
while($row = mysqli_fetch_array($result)){
echo '<option value="'.$row['id_marka'].'">'.$row['marka'].'</option>';}
?></select><br>
Модел:
<select name="model" id=model>
<option >--изберете--</option>
</select><br>
Екстри:<br>
<?php
include "config.php";
$result =mysqli_query($dbConn, "SELECT id_ekstra,ekstra FROM ekstri");
while($row = mysqli_fetch_array($result)){
echo '<input type="checkbox" style="width:10%" name="ekstri[]"value="'.$row['id_ekstra'].'">
<label for="'.$row['id_ekstra'].'">'.$row['ekstra'].'</label>';}
?>
<input type="submit" name="submit" value="Търси">
</form>
</div>
<?php
include "config.php";
if (isset($_POST["submit"])){
$marka=$_POST['marka'];
$model=$_POST['model'];
if($marka=="--изберете--"){$marka='';}
if($model=="--изберете--"){$model='';}
$ekst=" ";
if(!empty($_POST['ekstri'])){
$ekstri=$_POST['ekstri'];
$count=0;
for ($x = 0; $x < sizeof($ekstri); $x++){
$u=$ekstri[$x];
if($x==0){
$ekst=$ekst." ".$u;}
else{$ekst=$ekst." ,".$u;}
$count=$count+1;
}
}
if ( !empty($marka)&&!empty($model)&&!empty($ekstri)) {
$sql="Select koli.id_kola,snimka,marka,model from koli
join model on model.id_model=koli.id_model
join marka on marka.id_marka=model.id_marka
join koli_ekstri on koli_ekstri.id_kola=koli.id_kola
join ekstri on ekstri.id_ekstra=koli_ekstri.id_ekstra
where marka.id_marka=".$marka." AND model.id_model=".$model."AND koli_ekstri.id_ekstra in(".$ekst.") GROUP BY koli.id_kola HAVING COUNT(DISTINCT koli_ekstri.id_ekstra) =".$count.";";
}
else if ( empty($marka)&&empty($model)&&empty($ekstri)) {
$sql="Select id_kola,snimka,model,marka from koli join model on model.id_model=koli.id_model join marka on marka.id_marka=model.id_marka;";
}
else if ( !empty($marka)&&!empty($model)) {
$sql="Select id_kola,snimka,model,marka from koli join model on model.id_model=koli.id_model join marka on marka.id_marka=model.id_marka where marka.id_marka=".$marka." AND model.id_model=".$model.";";
}
else if ( !empty($marka)&&!empty($ekstri)) {
$sql="Select koli.id_kola,snimka,model,marka from koli join model on model.id_model=koli.id_model join marka on marka.id_marka=model.id_marka join koli_ekstri on koli_ekstri.id_kola=koli.id_kola where marka.id_marka=".$marka." AND koli_ekstri.id_ekstra in(".$ekst.") GROUP BY koli.id_kola HAVING COUNT(DISTINCT koli_ekstri.id_ekstra) =".$count.";";
}
else if ( !empty($marka)) {
$sql="Select koli.id_kola,snimka,model,marka from koli join model on model.id_model=koli.id_model join marka on marka.id_marka=model.id_marka where marka.id_marka=".$marka.";";
}
else if ( !empty($ekstri)) {
$sql="Select koli.id_kola,snimka,model,marka from koli join model on model.id_model=koli.id_model join marka on marka.id_marka=model.id_marka join koli_ekstri on koli_ekstri.id_kola=koli.id_kola where koli_ekstri.id_ekstra in(".$ekst.") GROUP BY koli.id_kola HAVING COUNT(DISTINCT koli_ekstri.id_ekstra) =".$count.";";
}
$call2 = $dbConn->prepare($sql);
if (!$call2->execute()){echo "Грешка.";}
else {
mysqli_stmt_store_result($call2);
mysqli_stmt_bind_result($call2,$id,$snimka,$model,$marka);
echo '<table border="5">
<thead>
<tr>
<th>Снимка</th>
<th>Марка</th>
<th>Модел</th>
<th>Екстри</th>
</tr>
</thead>
<tbody>';
while(mysqli_stmt_fetch($call2)){
echo '<tr>
<td id="'.$id.'snimka"><img src="uploads/'.$snimka.'"width="300"
height="200" ></td>
<td id="'.$id.'marka">'.$marka.'</td>
<td id="'.$id.'model">'.$model.'</td>';
$dbConn->next_result();
$call4 = $dbConn->prepare("SELECT ekstra from ekstri join koli_ekstri on koli_ekstri.id_ekstra=ekstri.id_ekstra where koli_ekstri.id_kola=?");
$call4->bind_param("i", $id);
if (! $call4->execute()){echo "Грешка.";}
else {
mysqli_stmt_store_result($call4);
mysqli_stmt_bind_result($call4, $ekstra);
echo '<td id="'.$id.'ekstra">';
while(mysqli_stmt_fetch($call4)){
echo $ekstra.', '; }
}
echo'</td></tr>';
}
echo ' </tbody>
</table>';
}
}
?>
</center>
<?php
$call = $dbConn->prepare("SELECT model,id_model,id_marka from model Order by id_marka;");
if (! $call->execute()){echo "Грешка.";}
else {
mysqli_stmt_store_result($call);
mysqli_stmt_bind_result($call, $model,$id_model,$id_marka);
echo'<script> ';
$i=0;
$id=0;
while(mysqli_stmt_fetch($call)){
if($id_marka!=$id){
echo 'var ar'.$id_marka.'=[];'; $id=$id_marka;}
echo 'ar'.$id_marka.'.push('.$id_model.');';
$i++;
echo 'ar'.$id_marka.'.push("'.$model.'");'; }
$i++;
}
echo'</script>';
?>
<script>
function change() {
var x =document.getElementById("marka").value;
var str=" <option >--изберете--</option>";
if(x!="--изберете--"){
for (i = 0; i < eval('ar'+x).length; i++) {
str+=" <option value='"+eval('ar'+x)[i]+"' >";
i++;
str+=eval('ar'+x)[i]+"</option>";
}
}
document.getElementById("model").innerHTML = str;
}
</script>
</body>
</html>