FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Make search engine With PHP and mySQL, for your site





puccavn
Learn how to make a search engine using the power of PHP and mySQL.

Here is an useful script that anyone can use to search a mySQL database and spit out the results as you want them. They have to be broken down into two separate files. One is an HTML form with action leading to the script PHP file. Lets work on the form first because it is the easiest.

Here is what we have to write in English for the Form:

Dec
Insert the values into the correct database.
Get a conformation that it has been uploaded
Here it is in PHP:

Search:


<form method="post" action="search.php">
<input type="text" name="search" size=25 maxlength=25>
<input type="Submit" name="Submit" value="Submit">
</form>

And that is basically all the code we have to write for the form. Now the hard part, writing the processing, which isn't really as hard as it seems. Here is what we have to write in English for the Processing:

Connect to the server and select the right database.
Grab the result, as you can see, its a fairly obvious line of code.
Run a while loop running the results we got.
Define each result a variable and spit it out.
Else say "Nothing Found"
Here it is in PHP:

<?
//connect to server
mysql_pconnect("server","server","password");
//select the db
mysql_select_db("database");
//get the results and store them in $result
$result = mysql_query ("SELECT * FROM whatevertable WHERE
whatevercolumn LIKE '%$search%'");
//run the while loop
while($r=mysql_fetch_array($result))
{
//grab the result
$whatevercolumn=$r["whatevercolumn"];
//print it out
echo $whatevercolumn;
echo "<br>";
}
//else nothing is found
else
{
echo "Nothing found";
}
?>

Couple of things: You have to rename the the name and password for the connection to the mySQL. You have to change the database name. Also change the whatevertable and whatevercolumn to the right table and column you want to search from. That's about it!
Guest
So your search engine is going to search a particular column of a particular table in one database!!!! That is not what I call as search engine atleast.

And I haven't ever heard of "else" in a while loop (while-else) in php (or any other language for that matter).
kv
Anonymous wrote:
So your search engine is going to search a particular column of a particular table in one database!!!! That is not what I call as search engine atleast.

And I haven't ever heard of "else" in a while loop (while-else) in php (or any other language for that matter).


Ok it was my post. I didn't observe I hadn't logged in.
WickedGravity
I appreciate all the fine material that people are posting, but...

If you are going to post a tutorial from another site, like the one above, could you please post the link to the site so that it can at least be verified from there.

Possibly check to see if any issues have arisen with the script/tutorial?
puccavn
this script use only for dynamic website
that use database to build your site
if your site is static website
don't use it Very Happy Laughing
Related topics
Yahoo developing an audio search engine!
PHP, MySQL...
Basic Search Engine Optimizing
Integrate Personal search engine
FREE SEO - Search Engine Optimization Canada Blog
Add search bar in my site
~~total SEARCH ENGINE OPTIMIZATION for your site!~~
Search Engine
Putting a search box on your site
advanced search engine
Creating a good search engine
PHP search function with MySQL fulltext
how to create my own search engine?
How to Have your Own search Engine on Your Site
Reply to topic    Frihost Forum Index -> Miscellaneous -> Tutorials

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.