Jump to content

Database Search Engine


sharpshoot3r

Recommended Posts

Hey, brother I will remember you that google or other search engine is quite another thing.

I will give you a simple but good search engine system:

 

Make this as a test, later modify this increasing columns, adding contents to them, feel free as you need.

 

To seach dinamically we need a form (SAVE THIS AS "search_form.html"):

 

<HTML>

<HEAD>

<TITLE>Search Engine</TITLE>

</HEAD>

<BODY>

<form method="POST" action="search.php">

Word: <input type="text" size="80" name="word"><br />

<input type="submit" value="Search">

</form>

</BODY>

</HTML>

 

Now the script: (SAVE THIS AS "search.php" it's the action!):

 

First create a database (if you have a one use this)

Create the table "news"

Create three field: "code", "title" and "news"

 

<?php

if(!empty($_POST['word'])) {

$word = str_replace(" ", "%", $_POST['word']);

 

// Alter the spaces adding a % symbol

 

mysql_connect('yourserver','user','password');

mysql_select_db('yourdatabase');

$query = "SELECT * FROM news WHERE news LIKE '%".$word."%' ORDER BY code DESC";

$sql = mysql_query($query); // Executes the query in the database

$total = mysql_num_rows($sql); // Counts the total of results found

echo "Your search returned: <strong>'$total'</strong> result(s). ";

while($result = mysql_fetch_array($sql)) { // Creates the Loop with the results

echo " ";

echo "<em><font color=\"blue\">".$result['news']."</em></font>";

}

}

?>

 

I hope I could help!

Man look at there

$total = 30($sql); // Counts the total of results found

and look there

Parse error: parse error, unexpected '(' in /home/hosting/lineageii/web/search.php on line 11

Where is the problem?

And what means that

I remember you that you must include contents to your database manually or create a way to do that by form.

Thanks in advince

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.