forked from kamalthakker/Skills_Endorsement_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
85 lines (50 loc) · 1.52 KB
/
test.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
<?php
//include_once '../dbconnection.php';
$db_servername = "localhost";
$db_username = "root";
$db_password = "root";
$db_name = "Skills_Endorsement";
$dbc = mysqli_connect($GLOBALS['db_servername'], $GLOBALS['db_username'], $GLOBALS['db_password'], $GLOBALS['db_name']) or die("Not connected..");
$q = "select * from skills";
if(isset($_POST['query'])){
// Now set the WHERE clause with LIKE query
$q .= ' WHERE title LIKE "%'.$_POST['query'].'%"';
}
if(isset($_REQUEST['query'])){
// Now set the WHERE clause with LIKE query
$q .= ' WHERE NAME like "%'.$_REQUEST['query'].'%"';
}
//echo $q;
//$r = mysqli_query($dbc,$q);
//mysqli_close($dbc); // close the connection
// User is found in DB
//$row = mysqli_fetch_array($r);
//return $row;
$return = array();
//if($result = $mysqli->query($q)){
if($result = mysqli_query($dbc,$q) ){
// fetch object array
while($obj = $result->fetch_object()) {
//$return[] = $obj->name;
//echo $obj->name;
$return[] = array('id' => $obj->skill_id, 'name' => $obj->name);
}
// free result set
$result->close();
}
// close connection
mysqli_close($dbc);
//$json = json_encode($return);
//echo json_encode($return);
//echo $return;
//print_r($json);
//print($json);
//echo $json;
//echo json_encode($return, JSON_PRETTY_PRINT);
$json = json_encode($return);
$File = 'skillsfile.json' ;
$fh = fopen($File, 'a') or die();
fwrite($fh,$json);
fclose($fh);
echo $json;
?>