-
Notifications
You must be signed in to change notification settings - Fork 2
/
topicsearch.php
64 lines (53 loc) · 1.36 KB
/
topicsearch.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
<?php
// Copyright © 2014 Max Penrose
?>
<?php
function writeResult($sqlArray, $i){ // prints the table cell
if(is_null($sqlArray)){
return ;
}
$classNum = ($i%2 == 0 ? 'c2':'c3');
$name = $sqlArray['name'];
$description = $sqlArray['descr'];
$uid = $sqlArray['uid'];
echo "
<tr class='$classNum'>
<td>
$name
</td>
<td>
$description
</td>
<td>
<form method='post'>
<input type='hidden' name='uid' value='$uid'>
<input type='submit' value='Add'>
</form>
</td>
</tr>
";
}
include 'private/pwds.php';
$q = $_GET['q'];
$conn = mysqli_connect('localhost',$mysqlUsername,$mysqlPassword,'revise');
$queryText = "select * from topics where LOWER(name) LIKE ('%$q%') LIMIT 1 OFFSET 0;";
$mquery = mysqli_query($conn, $queryText);
$array = mysqli_fetch_array($mquery, MYSQLI_ASSOC);
$topics = [$array];
writeResult($array, 1);
if(!is_null($array)){
$l=2;
while(!is_null($array)){
$o = $l-1;
$conn = mysqli_connect('localhost',$mysqlUsername,$mysqlPassword,'revise');
$queryText = "select * from topics where LOWER(name) LIKE ('%$q%') LIMIT $l OFFSET $o;";
$mquery = mysqli_query($conn, $queryText);
$array = mysqli_fetch_array($mquery, MYSQLI_ASSOC);
$topics = array_merge($topics, [$array]);
writeResult($array, $l);
$l = $l + 1;
}
} else {
echo '<tr class="c3"><td colspan="3">No Results</td></tr>';
}
?>