473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

how to built a search engine

I am try to using PHP to built a search engine. My problem how to make a search engine that user not only can insert the keyword in text field but also can minimize the searching area by clicking at the option i provide.The most inportant is how to make the relationship between the option user choose and the keyword at test field
Sep 22 '06 #1
4 1707
tbb9216
16
it all depends on the type of search you want to do. are you having customers search a product, users, or are you trying to take on google?

say you are searching a product, your SQL would look something like:

$product = 'web dev book'

SELECT prodId, prodPrice,
prodDesc, prodTitle
FROM products
WHERE prodTitle LIKE '%$product%'

this is the most basic kind of search. to break it down, you are selecting the fields you want from the table 'products,' then you are matching $product to prodTitle using LIKE, which allows wildcards (%), so any title that has $product in it anywhere. the downside to this is if $product == 'a', it will return any title with 'a' anywhere in it.

if you want to have user selected query options to narrow down their selection, you could do:

$product = 'web dev book'

if ( $priceSwitch ) {
$where .= "AND prodPrice = '$prodSwitch'";
}
if ( $hardcoverSwitch ) {
$where .= "AND prodCover = 'hardcover'";
}
SELECT prodId, prodPrice,
prodDesc, prodTitle
FROM products
WHERE prodTitle LIKE '%$product%'
$where

this will append your $where to the end of the mysql query, adding the extra switches you want. you could also use OR instead of AND if it fits, and this same concept can be used elsewhere in the script to make it more dynamic.

if you are daring, you can use REGEX:

$product = '^web'

SELECT *
FROM products
WHERE prodTitle REGEX '$product'

this allows regex characters, so in this case it would look for any title that starts with 'web', as ^ is regex for the start of a line. there is some danger in this, as starting with a ? will draw and error, or having a [ without a ], so youll need to parse those. but this should at least get you off to a start.

let me know if you have more questions.

-tim
Sep 22 '06 #2
Below is my search engine code. Now i want to add on two radio option so that the searching can be minimize. What should i do?



<?php session_start();?>
<h2>Search</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">
Search for:
<input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="Operasi">Alat Operasi</option>
<Option VALUE="Balai">Alat Balai</option>
<Option VALUE="Komunikasi">Alat Komunikasi</option>


</Select>

<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>

<?
//This is only displayed if they have submitted the form

if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_select_db("inventory") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM listofitem WHERE upper($field) LIKE'%$find%'");


echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>NamaPeralatan</th><th>Motor</th><th>Alat Operasi</th><th>Alat Balai</th><th>Alat Komunikasi</th> </tr>";

//And we display the results
while($result = mysql_fetch_array( $data ))
{


echo "<tr><td>";
echo $result['ID'];
echo "</td><td>";
echo $result['NamaPeralatan'];
echo "</td><td>";
echo $result['Motor'];
echo "</td><td>";
echo $result['Operasi'];
echo "</td><td>";
}
echo "</table>";



//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
Sep 23 '06 #3
tbb9216
16
2 things i need to know.

1) what is this a search for, if i understand the language i can help more

2) what do you want the radio buttons to do?

let me know this and i can tell you how to do it
Sep 23 '06 #4
2 things i need to know.

1) what is this a search for, if i understand the language i can help more

2) what do you want the radio buttons to do?

let me know this and i can tell you how to do it
In the column of Motor it will be catagorize to WithMotor and UnMotor tools.Thus the function of radio is let user can choose either the tools are type of WithMotor or UnMotor.

When the user key in the keywords in the textfield, the engine will search either the term is from WithMotor or UnMotor, then what categories it come from whether from OperationTool, OfficeTools or ComunicaionTools


CREATE TABLE `listofitem` `ID` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`NameOfTool` VARCHAR( 30 ) NOT NULL ,
`Motor` VARCHAR( 10 ) NULL DEFAULT NULL ,
`Operation` VARCHAR( 30 ) NULL DEFAULT NULL ,
`Office` VARCHAR( 30 ) NULL DEFAULT NULL ,
`Comunication` VARCHAR( 30 ) NULL DEFAULT NULL

<?php session_start();?>
<h2>Search</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">
Search for:
<input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="Operation">OperationTool</option>
<Option VALUE="Office">OfficeTools</option>
<Option VALUE="Comunication">ComunicationTools</option>


</Select>

<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>

<?
//This is only displayed if they have submitted the form

if ($searching="yes")

echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_select_db("inventory") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM listofitem WHERE upper($field) LIKE'%$find%'");


echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>NameOfTools</th><th>Motor</th><th>Alat Opeation</th><th>OfficeTools</th><th>ComunicationTools</th> </tr>";

//And we display the results
while($result = mysql_fetch_array( $data ))
{


echo "<tr><td>";
echo $result['ID'];
echo "</td><td>";
echo $result['NameOfTools'];
echo "</td><td>";
echo $result['Motor'];
echo "</td><td>";
echo $result['Operation'];
echo "</td><td>";
echo $result['Comunication'];
echo "</td><td>";
}
echo "</table>";



//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;

?>
Sep 23 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Rod | last post by:
Hi, i am doing a ecommerce website and would like to implement a search engine to find products. All the serach engine I have found on the web are parsing html page! This is not what i want. i...
0
by: R. Rajesh Jeba Anbiah | last post by:
Q: Is PHP search engine friendly? Q: Will search engine spiders crawl my PHP pages? A: Spiders should crawl anything provided they're accessible. Since, nowadays most of the websites are been...
11
by: Petre Huile | last post by:
I have designed a site for a client, but they have hired an internet marketing person to incrase their search engine ranking and traffic. He wants to put extra-large fonts on every page which will...
5
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
2
by: Patrick | last post by:
Are the differences between a search engine, a subject directory and a meta search engine significant for an ebusiness web site owner? A meta search engine merely uses ordinary existing search...
5
by: Sam | last post by:
Does anyone know of a way to create a search page under ASP.NET 2.0? I have started out by configuring a catalog in Index Server, registering the aspx, ascx extensions in the registry to allow...
3
by: hazly | last post by:
I'm very new in the web technology and need advice on search engine. I want to develop a portal using PHP and MySQL on Linux. Need to know on the following features : 1. search engine that could...
4
by: MDW | last post by:
Posted this on another board, but evidently it was off-topic there...hope you folks will be able to provide some guidance. I've been working on a Web site for a business (my first non-personal...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.