Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 11-02-2009, 07:32 AM
  #1
Ruriko
Fighter (Level 4)
 
Join Date: Mar 2006
Posts: 40
iTrader: (0)
Ruriko is an unknown quantity at this point
search help

hi I'm a newbie to php and I found a nice simple search engine script but the problem is if it can't find something it shows
Quote:
Results

Sorry, your search: "gd" returned zero results

Click here to try the search on google

You searched for: "gd"
Results

Next 10 >>

Showing results 1 to 0 of 0
I want to remove Results

Next 10 >>

Showing results 1 to 0 of 0

how can I do this?

PHP Code:
<?php

  
// Get the search variable from URL

  
$var = @$_GET['q'] ;
  
$trimmed trim($var); //trim whitespace from the stored variable

// rows to return
$limit=10

// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo 
"<p>Please enter a search...</p>";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo 
"<p>We dont seem to have a search parameter!</p>";
  exit;
  }

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("localhost","root",""); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("bazaar") or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$query "select * from products where name like \"%$trimmed%\"  
  order by productID"
// EDIT HERE and specify your table and field names for the SQL query

 
$numresults=mysql_query($query);
 
$numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
  echo 
"<h4>Results</h4>";
  echo 
"<p>Sorry, your search: &quot;" $trimmed "&quot; returned zero results</p>";

// google
 
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>"
;
  }

// next determine if s has been passed to script, if not use 0
  
if (empty($s)) {
  
$s=0;
  }

// get results
  
$query .= " limit $s,$limit";
  
$result mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: &quot;" $var "&quot;</p>";

// begin to show results set
echo "Results <br />";
$count $s ;

// now you can display the results returned
  
while ($rowmysql_fetch_array($result)) {
  
$title $row["name"];

  echo 
"$count.)&nbsp;$title <br />" ;
  
$count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  
echo "<br />";

  
// next we need to do the links to other results
  
if ($s>=1) { // bypass PREV link if s is 0
  
$prevs=($s-$limit);
  print 
"&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a>&nbsp&nbsp;"
;
  }

// calculate number of pages needing links
  
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

  
if ($numrows%$limit) {
  
// has remainder so add one page
  
$pages++;
  }

// check to see if last page
  
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  
// not last page so give NEXT link
  
$news=$s+$limit;

  echo 
"&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
  }

$a $s + ($limit) ;
  if (
$a $numrows) { $a $numrows ; }
  
$b $s ;
  echo 
"<p>Showing results $b to $a of $numrows</p>";
  
?>
Ruriko is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 11:27 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.