A search site script
Moderator: General Moderators
-
brand_beatrice
- Forum Newbie
- Posts: 10
- Joined: Tue Aug 30, 2005 5:43 am
- Location: London
- Contact:
A search site script
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?
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
What's "the way it should be"? Please be more specific.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?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
http://www.hotscripts.com has plenty
-
brand_beatrice
- Forum Newbie
- Posts: 10
- Joined: Tue Aug 30, 2005 5:43 am
- Location: London
- Contact:
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
-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
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
like they said: look around for one on http://www.hotscripts.com
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?
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?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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;
Last edited by John Cartwright on Tue Sep 13, 2005 12:36 pm, edited 3 times in total.
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();
}
}Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
so, to sum this up:
Assuming I have a button called "search", this is what the code should look like?
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();
}
}
}
?>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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Howdy,
I'm going to rehash this topic once more, just to um... get results.
This is the address that displays in the address bar:
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 -->Code: Select all
http://www.advantageboard.com/includes/search.php?q=executives&search=Searchand 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
to
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");Code: Select all
//search from where?
$search_string = $searchresults["Article_Text"];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?
$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?
Try:
(untested)
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);
}
}
?>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.
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.