-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
52 lines (46 loc) · 1.19 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
<?php
$servername = "localhost";
$username = "db_user";
$password = "db_pass";
$dbname = "db_name";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
function get_items($id = NULL) {
global $conn;
$context = array();
$featured = get_featured();
$published_array = array();
foreach ($featured as $place) {
$published_array[] = $place['item_id'];
}
$query = "SELECT * FROM `sortable`";
if (isset($id)) {
$query .= "WHERE `id` LIKE '$id'";
}
$query .= " ORDER BY `position`";
$query = $conn->query($query);
while ($row = mysqli_fetch_assoc($query)) {
if (!in_array($row['id'],$published_array)) {
$context[] = $row;
}
}
return $context;
}
function get_featured($place = NULL) {
global $conn;
$context = array();
$query = "SELECT * FROM `sortable`
INNER JOIN `published` ON `published`.`item_id` = `sortable`.`id`";
if (isset($place)) {
$query .= "WHERE `published`.`place` LIKE '$place'";
}
$query = $conn->query($query);
while ($row = mysqli_fetch_assoc($query)) {
$context[] = $row;
}
return $context;
}