Page 1 of 2

A search site script

Posted: Mon Sep 05, 2005 7:10 am
by brand_beatrice
hi everybody,

i am looking for a good search script for my portal: http://www.bicestertown.co.uk
i have tried Google before but it doesn't work the way it should be.
Any idea is welcome.
Thank you?

Re: A search site script

Posted: Mon Sep 05, 2005 8:08 am
by patrikG
brand_beatrice wrote:hi everybody,

i am looking for a good search script for my portal: http://www.bicestertown.co.uk
i have tried Google before but it doesn't work the way it should be.
Any idea is welcome.
Thank you?
What's "the way it should be"? Please be more specific.

Posted: Mon Sep 05, 2005 9:53 am
by John Cartwright

Posted: Mon Sep 05, 2005 3:27 pm
by brand_beatrice
As I can see this is the most discussed subject into this forum so far. Nobody has responded to this subject the way it should:

-free scripts, simple to setup without a MySQL necessity.

I am myself looking for a good search script. Haven’t found a good one so far. Don't want to see or hear about that Google search script. Is not good. If you come up with an idea or a script that you have used before please, make sure that is an easy to install one, simple, not MySQL(as 80% of us do not poses MySQL knowledge), free of advertisements and please, please, not Google.
Thank you.
PS
This is the portal where I try to implement that search box.
http://www.bicestertown.co.uk

Posted: Mon Sep 05, 2005 6:45 pm
by jayshields
like they said: look around for one on http://www.hotscripts.com

Posted: Tue Sep 06, 2005 3:48 pm
by $var
So I've been to hotscripts, and I see all these interfaces that you can download, but is there not a script you can write into a page?

I know you can write a SELECT * WHERE * LIKE * statement that searches a table in the database, which you can display on a second results page. I have pieces of this code, but nothing that has ever turned out results...

But I have seen it in action... and at one point in time, it worked... but I lost the results page...

Do any MySQL wizzes out there know about this?

Posted: Tue Sep 06, 2005 4:29 pm
by John Cartwright

Code: Select all

//get this string from form?
$search_terms = 'Some String Goes here';

//should allow user to match all terms of any terms
$match_all = true;

//put terms into array
$search_array = explode(' ',$search_terms);

//setup query
$sql = 'SELECT * FROM `table` WHERE ';

//Get number of elements searching for, for the for() clause
$count = $search_array;

//loop through elements
for ($x=0; $x <= $count; $x++) {
   //check if element is more than 2 characters
   //if this check is not performed likely you'll get unwanted results
   //because the 1-2 letter combination may come up frequently
   if (strlen($search_array[$x]) > 2) { 
      //have to control AND's or OR's because last element should have it added
      $sql .= '`column_that_your_searching_for` LIKE %'.$search_array[$x].'%'.($x == $count ? '',($match_all ? 'AND ', 'OR '));
   }
}

echo $sql;

Posted: Tue Sep 06, 2005 4:30 pm
by pickle
If you're using a MySQL database, it's quite easy, and can be done with just one function. Here it is roughly. Some of this is pseudo-code, so adapt it to your needs

Code: Select all

function do_search($search_string)
{
   create_connection_to_database()

   //this is the "SELECT * WHERE ..." part
   $query_string = make_query($search_string);

   //this does the query and returns the results
   $query_results = do_query($query_string);

   loop_through_each_result
   {
      output_each_row();
   }
}

Posted: Tue Sep 13, 2005 9:21 am
by $var
so, to sum this up:

Assuming I have a button called "search", this is what the code should look like?

Code: Select all

<? 
	if($_POST['bpress']=="search")
	{
		function do_search($search_string)
		{
	   create_connection_to_database()
	
	   //this is the "SELECT * WHERE ..." part
	   $query_string = make_query($search_string);

	   //this does the query and returns the results
	   $query_results = do_query($query_string);

	   loop_through_each_result
			{
    	  output_each_row();
	  		}
		}
	} 
?>

Posted: Tue Sep 13, 2005 11:37 am
by pickle
That's the jist of it, yes. However, the code I gave you isn't actual PHP code, it's just pseudo-code (more to convey the logic behind what you need to do, rather than working code). You'll have to change that to actual code before it'll work.

Posted: Tue Oct 18, 2005 8:43 am
by $var
Howdy,

I'm going to rehash this topic once more, just to um... get results.

Code: Select all

<?
    if($_POST['bpress']=="search")
    {
        function do_search($search_string)
        {
       	
		//setup query
		$sql = 'SELECT * FROM articles WHERE Article_Active = 0 ';
		$numrecord = mysql_query($sql);
		$numrecords = mysql_fetch_array($numrecord);
		$result = mysql_query($sql) or die (mysql_error()); 
		$searchresults = mysql_fetch_array($result);		
       
		//search from where?
	   	$search_string = $searchresults("Article_Text");
	   
	   //get this string from form?
		$search_terms = $search_string;

		//should allow user to match all terms of any terms
		$match_all = true;
		
		//put terms into array
		$search_array = explode(' ',$search_terms);
		
        $totalpages = intval(($numrecords[0])/$intRecsPerPage);
            {
				if($x >= $numrecords[0])
					{
						break;
					}
						print($search_array);
        	}
 		}
	}
?>

Code: Select all

<!-- SITE SEARCH -->
				<form method="GET" action="http://www.advantageboard.com/includes/search.php">
					  <input class="text" type=text name=q size=20 maxlength=255 value="">
					  <input class="text" type="submit" name="search" value="Search">     	  
				</form>		
				<!-- END SiteSearch  -->
This is the address that displays in the address bar:

Code: Select all

http://www.advantageboard.com/includes/search.php?q=executives&search=Search

Posted: Tue Oct 18, 2005 8:47 am
by patrikG
and the problem being?

Looking at your code I would think that $search_string is empty. Reason: $searchresults is an array (as you're using mysql_fetch_array), yet you treat it as a function call with one parameter "Article_Text".

In your code change

Code: Select all

//search from where?
           $search_string = $searchresults("Article_Text");
to

Code: Select all

//search from where?
           $search_string = $searchresults["Article_Text"];

Posted: Tue Oct 18, 2005 9:00 am
by $var
sorry, the problem being that nothing returns... even when i changed the string to the word 'executive' and searched executive.... nothing displayed.

$search_string = $searchresults("Article_Text");
$search_string = $searchresults["Article_Text"];

still doesn't do it... would you suspect that it has to do with they way it is being output, and that it just isn't reading the results?

Posted: Tue Oct 18, 2005 9:11 am
by patrikG
Try:

Code: Select all

<?php
        function do_search($search_string){
        if($_POST['bpress']=="search"){
//modified the query as you were doing a simple select. This query should do a search for $search_string
            $sql = 'SELECT Article_Text FROM articles WHERE Article_Active = 0 AND Article_Text LIKE %'.mysql_real_escape_string($search_string).'%';
            $result = mysql_query($sql) or die (mysql_error());
            $numRows = mysql_num_rows($result);
            $totalpages = integer($numRows/$intRecsPerPage);
            while($searchresults = mysql_fetch_array($result)){
                        print($searchresults);
            }
        }
?>
(untested)

Posted: Tue Oct 18, 2005 10:24 am
by $var
hi again...

it returns a similar blank page.
the script is much neater looking though :)

Here's a question:

It's returning to the same page, should there be a seperate results page,
or like, a duplicated Search page that it could send to?

My limited understanding of Search scripts is that it usually passes the info to another page,
but I would have thought that that would just be for organization.