-
Notifications
You must be signed in to change notification settings - Fork 4
/
search.php
38 lines (29 loc) · 1.01 KB
/
search.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
<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=Sharing user=postgres password=cs2102")
or die('Could not connect: HERE' . pg_last_error());
$q = $_GET["q"];
if (strlen($q)>0) {
$hint="";
$query = 'select distinct o.category, o.itemname, o.description, o.price, o.owner, a.auctionid
from object o, auction a where o.availability=TRUE and a.objectid = o.productid';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
while ($row = pg_fetch_row($result)){
if(stristr($row[1], $q)){
if($hint==""){
$hint = "<a href='browsing.php#id".$row[5]."'><u>".
$row[0]."</u> <br/> ".$row[1].": $".$row[3]."</a><hr>";
} else {
$hint = $hint . "<a href='browsing.php#id".$row[5]."'><u>".
$row[0]."</u> <br/> ".$row[1].": $".$row[3]."</a><hr>";
}
}
}
}
if ($hint=="") {
$response="no suggestion";
} else {
$response=$hint;
}
//output the response
echo $response;
?>