-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
203 lines (186 loc) · 5.69 KB
/
function.php
File metadata and controls
203 lines (186 loc) · 5.69 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
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
<?php
//calling db_connection page
include("connection.php");
function getAllProductShow()
{
global $conn;
// $sql = "SELECT * FROM product WHERE status=1 ORDER BY p_id DESC";
$sql= "SELECT product.*,category.* FROM product JOIN category ON product.c_id = category.c_id WHERE status=1 ORDER BY p_id LIMIT 6";
$query = mysqli_query($conn, $sql);
if (mysqli_num_rows($query)) {
$data = mysqli_fetch_all($query, MYSQLI_ASSOC);
return $data;
}
else
{
return false;
}
}
//fetch category
function fetchCategory() {
global $conn;
$query = "SELECT * FROM category";
$result = mysqli_query($conn, $query);
$categories = [];
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$categories[] = $row;
}
}
return $categories;
}
function getAllCategories() {
global $conn;
$query = "SELECT * FROM categories";
$result = mysqli_query($conn, $query);
$categories = [];
if ($result) {
while ($row = mysqli_fetch_assoc($result)) {
$categories[] = $row;
}
}
return $categories;
}
// ==================== fetch Advertisement =====================
function fetchAdvertisement()
{
global $conn;
$sql = "SELECT * FROM advertisement where status=1";
$query = mysqli_query($conn, $sql);
if (mysqli_num_rows($query) > 0)
{
$data = mysqli_fetch_all($query, MYSQLI_ASSOC);
return $data;
}
else
{
return false;
}
}
// ==================== counting the number of product in cartlist =====================
function getUserCartCount()
{
global $conn;
$user_id=$_SESSION['id'];
$sql = "SELECT count(p_id) as total_cart FROM cart where u_id=$user_id";
$query = mysqli_query($conn, $sql);
$data=mysqli_fetch_assoc($query);
return $data['total_cart'];
}
// ==================== fetch cartlist =====================
function showCart($user_id)
{
global $conn;
$sql = "SELECT product.* FROM product JOIN cart ON product.p_id = cart.p_id WHERE cart.u_id='".$user_id."'";
$query = mysqli_query($conn, $sql);
if ($query && mysqli_num_rows($query) > 0) {
$data = mysqli_fetch_all($query, MYSQLI_ASSOC);
return $data;
} else {
return []; // Return an empty array instead of false
}
}
// ==================== remove product from cart =====================
function cartRemove($product_id)
{
global $conn;
$sql = "DELETE FROM `cart` WHERE p_id='" . $product_id . "'";
$query = mysqli_query($conn, $sql);
if ($query) {
return true;
} else {
return false;
}
}
// ==================== product quantity upadtion in cartlist page =====================
function updateCartQuantity($user_id, $product_id, $quantity) {
global $conn;
$sql = "UPDATE cart SET quantity = '$quantity' WHERE u_id = '$user_id' AND p_id = '$product_id'";
return mysqli_query($conn, $sql);
}
// =========================== function for wishlist page ==================
function productDuplicacyCheckWishlist($user_id, $product_id)
{
global $conn;
// // session_start();
// $user_id=$_SESSION['id'];
$sql = "SELECT * FROM wishlist WHERE u_id=$user_id AND p_id = $product_id ";
$query = mysqli_query($conn, $sql);
if(mysqli_num_rows($query)>0)
{
return true;
}
else
{
return false;
}
}
// ========= remove from wishlist ==============
function wishlistRemove($product_id)
{
global $conn;
$sql = "DELETE FROM `wishlist` WHERE p_id='" . $product_id . "'";
$query = mysqli_query($conn, $sql);
if ($query) {
return true;
} else {
return false;
}
}
// Show all wishlist items for a user
function showWishlist($user_id) {
global $conn;
$query = "SELECT product.p_id, product.product_name, product.price, product.product_image FROM wishlist JOIN product ON wishlist.p_id = product.p_id WHERE wishlist.u_id = '$user_id'";
$result = mysqli_query($conn, $query);
$wishlistItems = [];
while ($row = mysqli_fetch_assoc($result)) {
$wishlistItems[] = $row;
}
return $wishlistItems;
}
// ==================== counting the number of product in cartlist =====================
function getUserWishlistCount(){
global $conn;
// session_start();
$user_id=$_SESSION['id'];
$sql = "SELECT count(p_id) as total_cart FROM wishlist where u_id=$user_id";
$query = mysqli_query($conn, $sql);
$data=mysqli_fetch_assoc($query);
return $data['total_cart'];
}
// check whether a product is in the cartlist or not
function isProductInCart($product_id,$user_id)
{
global $conn;
$sql = "SELECT * FROM cart WHERE u_id='".$user_id."' AND p_id ='".$product_id."' ";
$query = mysqli_query($conn, $sql);
if(mysqli_num_rows($query)>0)
{
return true;
}
else
{
return false;
}
}
function getUserDetails($user_id)
{
global $conn;
$sql = "SELECT * FROM `registration` WHERE id='" . $user_id . "'";
$query = mysqli_query($conn, $sql);
if (mysqli_num_rows($query)) {
$data = mysqli_fetch_assoc($query);
return $data;
} else {
return false;
}
}
// ==================== User's data update =====================
function UserUpdate($user_id, $first_name, $last_name, $username, $email,$dob,$mobile_no, $gender, $image)
{
global $conn;
$sql = "UPDATE `registration` SET first_name='" . $first_name . "',last_name='" . $last_name . "',gender='" . $gender . "',username='" . $username . "',email='" . $email . "',dob='".$dob."',mobile_no='".$mobile_no."',image='" . $image . "' WHERE id='" . $user_id . "'";
$query = mysqli_query($conn, $sql);
return $query ? true : false;
}
?>