-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.php
44 lines (33 loc) · 1.05 KB
/
product.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
<?php
// Use to fetch product data
class Product
{
public $db = null;
public function __construct(DBController $db)
{
if (!isset($db->con)) return null;
$this->db = $db;
}
// fetch product data using getData Method
public function getData($table = 'items'){
$result = $this->db->con->query("SELECT * FROM {$table}");
$resultArray = array();
// fetch product data one by one
while ($item = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$resultArray[] = $item;
}
return $resultArray;
}
// get product using item id
public function getProduct($item_id = null, $table= 'items'){
if (isset($item_id)){
$result = $this->db->con->query("SELECT * FROM {$table} WHERE item_id={$item_id}");
$resultArray = array();
// fetch product data one by one
while ($item = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$resultArray[] = $item;
}
return $resultArray;
}
}
}