-
Notifications
You must be signed in to change notification settings - Fork 0
/
Products.php
142 lines (132 loc) · 4.03 KB
/
Products.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
<?php
include 'connection.php';
include 'Header.html';
function favoriteCheck($product,$connection)
{
$fav="select * from favorites where user_id=".$_SESSION["uid"]." and product_id=".$product;
$resultfav = mysqli_query($connection,$fav);
if(!$resultfav)
{
echo mysqli_error($resultfav);
}
else {
if(mysqli_num_rows($resultfav)==0)
{
return 0;
}
else {
return 1;
}
}
}
$startrow = $_GET['startrow'];
if(strlen($_GET["search"])>=1)
{
$search = $_GET["search"];
$sql = "Select * FROM products Where name LIKE '%".$search."%'LIMIT ".$startrow.",10";
$currentlink = "Products.php?search=".$search;
}
else if($_GET["subtype"] ==null)
{
$type = $_GET["type"];
$sql = "Select * FROM products Where type = '".$type."'LIMIT ".$startrow.",10";
$currentlink = "Products.php?type=".$type."&subtype=&search=";
}
else if(isset($_GET["subtype"]))
{
$type = $_GET["type"];
$sub = $_GET["subtype"];
$sql = "Select * FROM products Where type = '".$type."' And subtype ='".$sub."'LIMIT ".$startrow.",10";
$currentlink = "Products.php?type=".$type."&subtype=".$sub."&search=";
}
$result = mysqli_query($con,$sql);
if (!$result) {
echo mysqli_error($con);
}
else {
if (mysqli_num_rows($result) == 0)
{
}
else{
if(!isset($startrow))
$startrow=0;
$maxrow=mysqli_num_rows($result);
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="ProductCSS.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<table id="catalog">
<!-- first tr has th for product and th for description-->
<tr>
<th><i>Product</i></th>
<th><i>description</i></th>
<th><i>Price</i></th>
</tr>
<?php
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$product_id = $row["id"];
$price=$row["price"];
$name=$row["name"];
$desc=$row["description"];
$type=$row["type"];
$subt=$row["subtype"];
$photo=$row["photo"];
$cents = $row["cents"];
$favorited = favoriteCheck($product_id,$con);
if($favorited==0)
{
$heartstatus="fa fa-heart-o";
}
else {
$heartstatus = "fa fa-heart";
}
?>
<tr>
<td><span id="decimalfont"><?=$name?></span><br><a href = "Purchases.php?id=<?=$product_id?>">
<img src="<?=$photo?>" width = "128" height = "128"></a></td>
<td><?=$desc?></td>
<td><b><span id="decimalfont"><?=$price?>,</span><?=$cents?>€</b>
<?php
if ($heartstatus=="fa fa-heart") {
$link = "removefromfav.php";
}
else {
$link = "addtofavorites.php";
}
?>
<a href="<?=$link?>?id=<?=$product_id?>"><i class="<?=$heartstatus?>" style="font-size:36px;float:right;color:red;"></i></a></td>
</tr>
<?php
}
}
}
?>
</table>
<?php
if ($startrow==0&&$maxrow==10) {
?>
<center><a href="<?=$currentlink?>&startrow=<?=$startrow+10?>"><i class="fa fa-arrow-circle-right" style="color:red;font-size:36px;"></i> </a></center>
<?php
}
else if ($maxrow==10) {
?>
<center><a href="<?=$currentlink?>&startrow=<?=$startrow-10?>"> <i class="fa fa-arrow-circle-left" style="color:red;font-size:36px;"></i> </a></center>
<center><a href="<?=$currentlink?>&startrow=<?=$startrow+10?>"><i class="fa fa-arrow-circle-right" style="color:red;font-size:36px;"></i> </a></center>
<?php
} else if($startrow>=10) {
?>
<center><a href="<?=$currentlink?>&startrow=<?=$startrow-10?>"><i class="fa fa-arrow-circle-left" style="color:red;font-size:36px;"></i> </a></center>
<?php
}
else {
}
?>
</body>
</html>