@import "http://lib.zetabin.com/jQuery/facebox/facebox.css";
|
Better search engine with Paginate
|
|
Topic Started: Jan 23 2009, 10:44 AM (119 Views)
|
|
php-coder
|
Jan 23 2009, 10:44 AM
Post #1
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
Hello,
I put this search engine together after giving Jakkis ago and not liking it, this search engine has paginate built in so you can either show 10, 20, 30, results per page entirely upto you, you only need to make some small edits these being your Database information. This also links to users profiles, i will be modifying it over time to search emails also, and then link some user info below the search results similair to how google displays its results.
- Code:
-
<form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form>
<?php
$var = @$_GET['q'] ; $s = $_GET['s']; $trimmed = trim($var);
$limit=10;
if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; }
if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; }
mysql_connect("HOSTNAME","USERNAME","PASSWORD"); // Make sure to enter your Hostname, Username & Password
mysql_select_db("login") or die("Unable to select database");
$query = "select * from TABLE where username like \"%$trimmed%\" // Make sure to add your table names here that you want to search order by username";
$numresults=mysql_query($query); $numrows=mysql_num_rows($numresults);
if ($numrows == 0) { echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\" target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here</a> to try the search on google</p>"; }
if (empty($s)) { $s=0; }
$query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query");
echo "<p>You searched for: "" . $var . ""</p>";
echo "Results :<br><br>"; $count = 1 + $s ;
while ($row= mysql_fetch_array($result)) {
$usersname = $row['username']; echo "<td><a href='userinfo.php?user=$usersname'>$usersname</a></div></td>"; echo "</tr>"; echo "</table>";
$count++ ; }
$currPage = (($s/$limit) + 1);
echo "<br /><br><br>";
if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev</a>  "; }
$pages=intval($numrows/$limit);
if ($numrows%$limit) { $pages++; }
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next >></a>"; }
$a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?>
Enjoy, Feel free to modify this, Any good modifications please post them up.
~Pc
|
|
|
| |
|
Admin
|
Jan 23 2009, 02:26 PM
Post #2
|
|
Administrator
- Posts:
- 303
- Group:
- Admins
- Member
- #1
- Joined:
- Mar 20, 2008
|
very nice
|
|
|
| |
|
php-coder
|
Jan 23 2009, 04:19 PM
Post #3
|
|
- Posts:
- 134
- Group:
- Contributor
- Member
- #39
- Joined:
- Dec 8, 2008
|
Its proving to be a pain in the butt to get it to show the users avatar aswell as there name and a link to there profile if anyone wants to give this a shot and keep us updated on your prgoress.
~Pc
|
|
|
| |
| 1 user reading this topic (1 Guest and 0 Anonymous)
|