-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
68 lines (42 loc) · 970 Bytes
/
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
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
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$search=$_POST['search'];
$dbc= mysql_connect('localhost','root','nitish2012');
mysql_select_db("articles");
if (!$dbc)
{
die('Could not connect:'. $dbc->error);
}
$query="SELECT * FROM articles WHERE title LIKE '%".$search."%' OR link LIKE '%".$search."%'";
$doQuery=mysql_query($query);
$numrows=mysql_num_rows($doQuery);
$i=0;
if($numrows>0)
{
while($result=mysql_fetch_assoc($doQuery))
{
$sno[$i]=$i;
$link_count[$i]=substr_count($result['link'],$search);
$link[$i]=$result['link'];
$title_count[$i]=substr_count($result['title'],$search);
$title[$i]=$result['title'];
$weight[$i]=$link_count[$i]+5*$title_count[$i];
$i++;
}
}
else
{
echo 'No results in database';
}
array_multisort($weight,$sno);
$k=1;
for($j=$i-1;$j>=0;$j--)
{
echo $k.'</br>';
echo $title[$sno[$j]].'</br>';
echo $link[$sno[$j]].'</br>';
$k++;
}
mysql_close($dbc);
?>