-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdishes.php
More file actions
120 lines (105 loc) · 2.75 KB
/
dishes.php
File metadata and controls
120 lines (105 loc) · 2.75 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
<?php
require_once("./components.php");
class Dish
{
//Properies
public $id;
public $type;
public $name;
public $description;
public $price_s;
public $price_l;
//METHODS
//SETTERS
function set_id($id)
{
$this->id=$id;
}
function set_type($type)
{
$this->type=$type;
}
function set_name($name)
{
$this->name=$name;
}
function set_description($description)
{
$this->description=$description;
}
function set_price_s($price_s)
{
$this->price_s=$price_s;
}
function set_price_l($price_l)
{
$this->price_l=$price_l;
}
//GETTERS function get_id()
function get_id()
{
return $this->id;
}
function get_type()
{
return $this->type;
}
function get_name()
{
return $this->name;
}
function get_description()
{
return $this->description;
}
function get_price_s()
{
return $this->price_s;
}
function get_price_l()
{
return $this->price_l;
}
}
//check connection
if($connect->connect_error)
{
die("Connection filed: ".$connect->connect_error);
}
//if connection is correct, then execute the class
else
{
$sql = 'SELECT id, type, name, description, price_s, price_l FROM dishes';
//if($result = $connect->query($sql))
if($result = mysqli_query($connect, $sql))
{
if(mysqli_num_rows($result) > 0)
{
//output data of each row
while($row = mysqli_fetch_assoc($result))
{
$dish[$row['id']] = new Dish();
$dish[$row['id']]->set_id($row["id"]);
$dish[$row['id']]->set_type($row["type"]);
$dish[$row['id']]->set_name($row["name"]);
$dish[$row['id']]->set_description($row["description"]);
$dish[$row['id']]->set_price_s($row["price_s"]);
$dish[$row['id']]->set_price_l($row["price_l"]);
makeCardDishes(
$dish[$row['id']]->get_id(),
$dish[$row['id']]->get_name(),
$dish[$row['id']]->get_description(),
$dish[$row['id']]->get_price_s(),
$dish[$row['id']]->get_price_l()
);
}
}
$result->free();
}
else
{
echo "result error!";
}
$connect->close();
}
?>