1 results= http://Www.google.com
but i dont know how to turn that result into a real link that u can actually clik on and will send you to the page..
Code: Select all
1. <?php
2.
3. // Get the search variable from URL
4.
5. $var = @$_GET['q'] ;
6. $trimmed = trim($var); //trim whitespace from the stored variable
7.
8. // rows to return
9. $limit=10;
10.
11. // check for an empty string and display a message.
12. if ($trimmed == "")
13. {
14. echo "<p>Please enter a search...</p>";
15. exit;
16. }
17.
18. // check for a search parameter
19. if (!isset($var))
20. {
21. echo "<p>We dont seem to have a search parameter!</p>";
22. exit;
23. }
24.
25. //connect to your database ** EDIT REQUIRED HERE **
26. mysql_connect("mysql host","user","pass"); //(host, username, password)
27.
28. //specify database ** EDIT REQUIRED HERE **
29. mysql_select_db("database") or die("Unable to select database"); //select which database we're using
30.
31. // Build SQL Query
32. $query = "select * from searchengine where keywords like \"%$trimmed%\"
33. order by id"; // EDIT HERE and specify your table and field names for the SQL query
34.
35. $numresults=mysql_query($query);
36. $numrows=mysql_num_rows($numresults);
37.
38. // If we have no results, offer a google search as an alternative
39.
40. if ($numrows == 0)
41. {
42. echo "<h4>Results</h4>";
43. echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";
44. }
45.
46. // next determine if s has been passed to script, if not use 0
47. if (empty($s)) {
48. $s=0;
49. }
50.
51. // get results
52. $query .= " limit $s,$limit";
53. $result = mysql_query($query) or die("Couldn't execute query");
54.
55. // display what the person searched for
56. echo "<p>You searched for: "" . $var . ""</p>";
57.
58. // begin to show results set
59. echo "Results";
60. $count = 1 + $s ;
61.
62. // now you can display the results returned (i think its here somewhere where ihave to make the change)
63. while ($row= mysql_fetch_array($result)) {
64. $title = $row["url"];
65.
66. echo "$count.) $title" ;
67. $count++ ;
68. }
69.
70. $currPage = (($s/$limit) + 1);
71.
72. //break before paging
73. echo "<br />";
74.
75. // next we need to do the links to other results
76. if ($s>=1) { // bypass PREV link if s is 0
77. $prevs=($s-$limit);
78. print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><<
79. Prev 10</a>  ";
80. }
81.
82. // calculate number of pages needing links
83. $pages=intval($numrows/$limit);
84.
85. // $pages now contains int of pages needed unless there is a remainder from division
86.
87. if ($numrows%$limit) {
88. // has remainder so add one page
89. $pages++;
90. }
91.
92. // check to see if last page
93. if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
94.
95. // not last page so give NEXT link
96. $news=$s+$limit;
97.
98. echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>";
99. }
100.
101. $a = $s + ($limit) ;
102. if ($a > $numrows) { $a = $numrows ; }
103. $b = $s + 1 ;
104. echo "<p>Showing results $b to $a of $numrows</p>";
105.
106. ?>