-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpfunctions.php
executable file
·142 lines (118 loc) · 3.96 KB
/
phpfunctions.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';
function createTableContent() {
global $connection;
$html = '';
$sql = 'SELECT * FROM andmed ORDER BY ID DESC';
if ($result = $connection -> query($sql)) {
$i = 1;
foreach ($result as $row) {
$html = $html . ' <div class="item">
';
$html = $html . ' <div class="counter-wrapper"><p>' . $i . '.</p></div>
';
$html = $html . ' <div class="item_values">
';
$html = $html . ' <div class="item_value"><input class="item_value" type="text" value="' . $row['thing1'] . '" disabled></div>
';
$html = $html . ' <div class="item_value"><input class="item_value" type="text" value="' . $row['thing2'] . '"disabled></div>
';
$html = $html . ' <div class="item_value"><input class="item_value" type="text" value="' . $row['thing3'] . '"disabled></div>
';
$html = $html . ' <input type="hidden" class="item_id" value="' . $row['ID'] . '">
';
$html = $html . ' </div>
';
$html = $html . ' <div class="item_buttons">
';
$html = $html . ' <input class="item_action_edit" type="image" src="Edit.png">
';
$html = $html . ' <input class="item_action_delete" type="image" src="Delete.png">
';
$html = $html . ' </div>
';
$html = $html . '</div>
';
$i++;
}
} else {
echo $connection -> error;
}
return $html;
}
function createPopupContent() {
$html = '';
$html = $html . '<input type="text" name="thing1" id="thing1" class="changeable" disabled value="thing1">';
$html = $html . '<br>';
$html = $html . '<input type="text" name="thing2" id="thing2" class="changeable" disabled value="thing2">';
$html = $html . '<br>';
$html = $html . '<input type="text" name="thing3" id="thing3" class="changeable" disabled value="thing3">';
$html = $html . '<br>';
$html = $html . '<input type="hidden" name="item_id" class="item_id" value="null" disabled>';
$html = $html . '<br>';
return $html;
}
function createPopupContentForExistingItem($id) {
global $connection;
$html = '';
$sql = 'SELECT * FROM andmed WHERE ID = ' . $id;
if ($result = $connection -> query($sql)) {
foreach ($result as $row) {
$html = $html . '<input type="text" name="thing1" id="thing1" class="changeable" disabled value="' . $row['thing1'] . '">';
$html = $html . '<br>';
$html = $html . '<input type="text" name="thing2" id="thing2" class="changeable" disabled value="' . $row['thing2'] . '">';
$html = $html . '<br>';
$html = $html . '<input type="text" name="thing3" id="thing3" class="changeable" disabled value="' . $row['thing3'] . '">';
$html = $html . '<br>';
$html = $html . '<input type="hidden" name="item_id" class="item_id" value="' . $row['ID'] .'" disabled>';
$html = $html . '<br>';
}
} else {
//echo $connection -> error;
}
return $html;
}
function addItem($inputArray) {
global $connection;
$input1 = $inputArray[0];
$input2 = $inputArray[1];
$input3 = $inputArray[2];
$sql = 'INSERT INTO andmed (thing1, thing2, thing3)
VALUES (:thing1, :thing2, :thing3)';
if ($query = $connection -> prepare($sql)) {
$query -> bindParam(':thing1', $input1);
$query -> bindParam(':thing2', $input2);
$query -> bindParam(':thing3', $input3);
$query -> execute();
} else {
echo $connection -> error;
}
}
function deleteItem($id) {
global $connection;
$sql = 'DELETE FROM andmed WHERE id = :id';
if ($query = $connection -> prepare($sql)) {
$query -> bindParam(':id', $id);
$query -> execute();
} else {
echo $connection -> error;
}
}
function updateItem($id, $inputArray) {
global $connection;
$input1 = $inputArray[0];
$input2 = $inputArray[1];
$input3 = $inputArray[2];
$sql = 'UPDATE andmed
SET thing1 = :thing1, thing2 = :thing2, thing3 = :thing3
WHERE ID = :id';
if ($query = $connection -> prepare($sql)) {
$query -> bindParam(':thing1', $input1);
$query -> bindParam(':thing2', $input2);
$query -> bindParam(':thing3', $input3);
$query -> bindParam(':id', $id);
$query -> execute();
} else {
echo $connection -> error;
}
}