forked from sajjadsaleem341/Plant-Nest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
86 lines (68 loc) · 2.24 KB
/
functions.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
<?php
function get_safe_value($con,$str){
if($str!=''){
$str = trim($str);
return mysqli_real_escape_string($con,$str);
}
}
function get_product($con,$limit='',$cat_id='',$product_id='',$search_str='', bool $getQuery=false){
$sql = "select product.*,categories.Categories from product,categories where product.Status=1";
if($cat_id !== "") {
$sql.= " and Category_Id=$cat_id ";
}
if($product_id !== "") {
$sql.= " and product.Id=$product_id";
}
$sql.= " and product.Category_Id=categories.Id ";
if($search_str !== "") {
$sql.= " and (product.Name like '%$search_str%' or product.Description like '%$search_str%' or categories.Categories like '%$search_str%')";
}
$sql.= " order by product.Id desc ";
if($limit !== '') {
$sql.=" limit $limit";
}
if ($getQuery) {
return $sql;
}
$res=mysqli_query($con,$sql);
$data=array();
while($row=mysqli_fetch_assoc($res)){
$data[]=$row;
}
return $data;
}
function get_category($con, $limit='', $cat_id='', $search_str='', bool $getQuery=false) {
$sql = "SELECT * FROM categories WHERE Status=1"; // where 1=1 added to add more WHERE querie below
if (!empty($cat_id)) {
$sql .= " AND id = '".mysqli_real_escape_string($con, $cat_id)."'";
}
if (!empty($search_str)) {
$search_str = mysqli_real_escape_string($con, $search_str);
$sql .= " AND (name LIKE '%$search_str%' OR Categories LIKE '%$search_str%')";
}
if (!empty($limit)) {
$sql .= " LIMIT $limit";
}
if ($getQuery) {
return $sql;
}
$res = mysqli_query($con, $sql);
$categories = [];
while ($row=mysqli_fetch_assoc($res)) {
$categories[] = $row;
}
return $categories;
}
function productSoldQtyByProductId($con,$pid){
$sql="select sum(orders_detail.Qty) as Qty from orders_detail,orders where orders.Id=orders_detail.Order_Id and orders_detail.Product_Id=$pid and orders.Order_Status!=4";
$res=mysqli_query($con,$sql);
$row=mysqli_fetch_assoc($res);
return $row['Qty'];
}
function productQty($con,$pid){
$sql="select Qty from product where Id='$pid'";
$res=mysqli_query($con,$sql);
$row=mysqli_fetch_assoc($res);
return $row['Qty'];
}
?>