-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchSnippet.php
39 lines (31 loc) · 947 Bytes
/
searchSnippet.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
<?php
session_start();
include 'database/connect.php';
include 'functions.php';
protectAdmin();
$t = $_POST['title'];
$text = "%".$t."%";
$data = array();
$query = $con->prepare("SELECT id, user_id, title, description, syntax, public FROM snippets WHERE title LIKE ? LIMIT ?");
$query->bind_param("ss", $text, $numSnip);
$query->execute();
$query->store_result();
$query->bind_result($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['snippet_id'][] = $id;
$data['user_id'][] = $user_id;
$data['username'][] = $username;
$data['title'][] = $title;
$data['description'][] = $description;
$data['syntax'][] = $syntax;
$data['public'][] = $public;
}
$q->close();
$query->close();
echo json_encode($data);
?>