Creating a search engine

At the moment I am working on making a search engine for our website which will help the users be able to filter through the posts if they are looking for a specific topic or area of the website. I have managed to get a really basic one working but need to link it correctly to our database so we can search specific posts, however that should be easy to change.

search Above: How the search bar currently appears.

searching

Above: Showing that when no information is added, a message of ‘could not search!’ is given out


<?php
$output='';

if(isset($_POST["search"])) {
$searchq= $_POST["search"];

$query = mysql_query("SELECT * FROM posts WHERE firstname LIKE '%$searchq%' OR lastname LIKE '%searchq%'") or die("could not search!");

$count= mysql_num_rows($query);
if($count==0){
$output = 'There was no search results!';
}else{
while ($row=mysql_fetch_array($query)) {
$fname = $row['firstname'];
$lname =$row['lname'];

$output .='<div>'.$fname.''.$lname.'</div>';
}
}
}

?>
<!DOCTYPE html>

<html>

<head>

<title>Search</title>

</head>

<body>

<form action="index3.php" method="post">

<input type="text" name="search" placeholder="Search for members..."/>
<input type="submit" value=">>" />




</form>
<?php print("$output");?>

</body>
</html>

Below is a very useful video which I used to help me create this.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s