-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_related.php
executable file
·85 lines (72 loc) · 3.28 KB
/
get_related.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
<?php
session_start();
include_once "db_functions.php";
//get the q parameter from URL
$search_item=$_GET["search_item"];
$choosedb=$_GET["choosedb"];
$user_id=$_GET["user_id"];
$tag=$_GET["tag"];
$campus=$_GET["campus"];
$id_excluded=$_GET["id_excluded"];
//connect db
if (strlen($choosedb) > 0) {
$sql = "";
if ($choosedb == "Sales"){
$host_id_type = "SellerId";
$item_id_type = "SaleId";
$intended_id_type = "IntendedBuyerId";
}else{
$host_id_type = "BuyerId";
$item_id_type = "RequestId";
$intended_id_type = "SaleId";
}
$relation = ($campus != "") ? "(SELECT NetId FROM Users WHERE Campus='$campus') AS Temp JOIN $choosedb ON NetId=$host_id_type" : $choosedb;
if (strlen($search_item) > 0 || strlen($user_id) > 0 || strlen($tag) > 0) {
if (strlen($tag) > 0) {
$sql = "SELECT $item_id_type, Image, ProductName, IntendedPrice FROM $relation WHERE Tag = '$tag' AND $intended_id_type IS NULL".(($id_excluded) ? "AND $item_id_type <> $id_excluded":"")." ORDER BY DatePost DESC";
} else if (strlen($search_item) > 0) {
$sql = "SELECT $item_id_type, Image, ProductName, IntendedPrice FROM $relation WHERE ProductName LIKE '%$search_item%' AND $intended_id_type IS NULL ORDER BY DatePost DESC";
}else {
$sql = "SELECT $item_id_type, Image, ProductName, IntendedPrice FROM $relation WHERE $host_id_type = '$user_id' AND $intended_id_type IS NULL ORDER BY DatePost DESC";
}
}else {
$sql = "SELECT $item_id_type, Image, ProductName, IntendedPrice FROM $relation WHERE $intended_id_type IS NULL ORDER BY DatePost DESC LIMIT 4";
}
$conn = connectDB();
$result = $conn->query($sql);
$array=array();
if ($result){
while($row = mysqli_fetch_assoc($result)){
$array[]=$row;
}
}
$conn->close();
foreach($array as $val):
$image = ($val['Image']) ? $val['Image'] : 'images/beaconlogo.png';
$id = "";
if ($choosedb == "Sales"){
$id = $val['SaleId'];
}else{
$id = $val['RequestId'];
}
echo '
<div class="col-md-3 col-sm-4">
<div class="single-product">
<div class="product-block">
<img src="'.$image.'" alt="" class="thumbnail" height="320px">
<div class="related-product text-center">
<p class="title">'.$val['ProductName'].'</p>
<p class="price">$ '.$val['IntendedPrice'].'</p>
</div>
<div class="product-hover">
<ul>
<li><a href="single-product.php?Id='.$id.'&choosedb='.$choosedb.'"><i class="fa fa-cart-arrow-down"></i></a></li>
</ul>
</div>
</div>
</div>
</div>
';
endforeach;
}
?>