-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_helper.php
More file actions
44 lines (34 loc) · 1 KB
/
Copy pathdatabase_helper.php
File metadata and controls
44 lines (34 loc) · 1 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
<?php
define('DB', 'book-crossing');
define('TABLE', '`bx-book-ratings`');
define('USERID', '`User-ID`');
define('RATING', '`Book-Rating`');
define('ISBN', '`ISBN`');
global $mysqli;
$mysqli = mysqli_init();
$mysqli->real_connect('localhost', 'root', 'QnwDhcpugZHsxK5', DB);
function fetch_val($query) {
global $mysqli;
$result = $mysqli->query($query);
while ($row = $result->fetch_assoc()) {
return $row['field'];
}
}
function fetch_array($query) {
global $mysqli;
$result = $mysqli->query($query);
$return = array();
while ($row = $result->fetch_assoc()) {
$return[] = $row['field'];
}
return $return;
}
function fetch_user_ratings($user_id) {
global $mysqli;
$sql_result = $mysqli->query('SELECT `ISBN`, `Book-Rating` FROM `bx-book-ratings` WHERE `User-ID` = "' . $user_id . '" ORDER BY `ISBN`');
$result = array();
while ($row = $sql_result->fetch_assoc()) {
$result[$row['ISBN']] = $row['Book-Rating'];
}
return $result;
}