-
Notifications
You must be signed in to change notification settings - Fork 0
/
items.php
87 lines (82 loc) · 2.45 KB
/
items.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
<?php
class Items{
public function showItems(){
$dbObj = new DB_Class();
$db = $dbObj->connect();
$result = $db->query("SELECT * FROM items");
return $result;
}
public function addToBasket(){
$dbObj = new DB_Class();
$db = $dbObj->connect();
$result = $db->query("SELECT item_ids FROM basket");
$result = $result->fetch(PDO::FETCH_ASSOC);
$temp = $result['item_ids'];
if(!strstr($temp, $_GET['iid']) )
$temp.=$_GET['iid']." ";
$result2 = $db->query("UPDATE basket SET item_ids = '$temp'");
}
public function isInBasket($iid){
$dbObj = new DB_Class();
$db = $dbObj->connect();
$result = $db->query("SELECT item_ids FROM basket");
$result = $result->fetch(PDO::FETCH_ASSOC);
if(strstr($result['item_ids'], $iid) )
return true;
else
return false;
}
public function removeFromBasket($iid){
$dbObj = new DB_Class();
$db = $dbObj->connect();
$result = $db->query("SELECT item_ids FROM basket");
$result = $result->fetch(PDO::FETCH_ASSOC);
$temp = $result['item_ids'];
$temp = str_replace($_GET['iid'].' ', '', $temp);
$result2 = $db->query("UPDATE basket SET item_ids = '$temp'");
}
public function filterItems(){
$dbObj = new DB_Class();
$db = $dbObj->connect();
$query='SELECT * FROM items WHERE ';
if(!empty($_POST['priceA']) || $_POST['priceA'] == '0'){
if(empty($_POST['priceB'])){
$query.='price > '.$_POST["priceA"].' AND ';
} else{
$query.='price BETWEEN '.$_POST["priceA"].' AND '.$_POST["priceB"].' AND ';
}
} else{
if(empty($_POST['priceB']))
$query.='price > 0 AND ';
else
$query.='price < '.$_POST["priceB"].' AND ';
}
if(!empty($_POST['yearA']) || $_POST['yearA'] == '0'){
if(empty($_POST['yearB'])){
$query.='year > '.$_POST["yearA"].' AND ';
} else{
$query.='year BETWEEN '.$_POST["yearA"].' AND '.$_POST["yearB"].' AND ';
}
} else{
if(empty($_POST['yearB']))
$query.='year > 0 AND ';
else
$query.='year < '.$_POST["yearB"].' AND ';
}
if(!empty($_POST['horseA']) || $_POST['horseA'] == '0'){
if(empty($_POST['horseB'])){
$query.='horsepower > '.$_POST["horseA"].' ';
} else{
$query.='horsepower BETWEEN '.$_POST["horseA"].' AND '.$_POST["horseB"].' ';
}
} else{
if(empty($_POST['horseB']))
$query.='horsepower > 0 ';
else
$query.='horsepower < '.$_POST["horseB"].' ';
}
$result = $db->query($query);
return $result;
}
}
?>