-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadSnippets.php
42 lines (31 loc) · 977 Bytes
/
loadSnippets.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
<?php
session_start();
include 'database/connect.php';
include 'functions.php';
protectAdmin();
$pageNum = (int)$_POST['page'] - 1;
$position = $pageNum * $numSnip;
$data = array();
$query = $con->prepare("SELECT id, user_id, title, description, syntax, public FROM snippets LIMIT ?,?");
$query->bind_param("ii", $position, $numSnip);
$query->execute();
$query->store_result();
$query->bind_result($snippet_id, $user_id, $title, $description, $syntax, $public);
$q = $con->prepare("SELECT username FROM users WHERE user_id = ?");
while($query->fetch()){
$q->bind_param("s", $user_id);
$q->execute();
$q->bind_result($username);
$q->fetch();
$data['user_id'][] = $user_id;
$data['snippet_id'][] = $snippet_id;
$data['username'][] = $username;
$data['title'][] = $title;
$data['description'][] = $description;
$data['syntax'][] = $syntax;
$data['public'][] = $active;
}
$q->close();
$query->close();
echo json_encode($data);
?>