newrow

Simple search engine


<html>

<?php

$var = @$_GET['q'] ; // get the query for the search engine (if applicable)

$trimmed = trim($var); //trim whitespace from the stored variable



$user = "root"; // AN EDIT IS REQUIRED HERE

$password = "";

$host = "localhost";

$dbase = "system";

$table = "students";



// Connection to DBase

mysql_connect($host,$user,$pass);

@mysql_select_db($dbase) or die("Unable to select database");



$field_to_search = "FullName";

$query = "SELECT * FROM students WHERE FullName LIKE "%$trimmed%" ";



$result = mysql_query($query);

$count = mysql_numrows($result);

?>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>



<body>

<form name="search" method="GET" action="<?=$PHP_SELF?>">

Seach the database for: <input type="text" name="q" />

<input type="submit" name="search" value="Search" />

</form>



<?php

if ($trimmed == "")

{

echo "<p>Please enter a search...</p>";

exit;

}



// check for a search parameter

if (!isset($var))

{

echo "<p>We dont seem to have a search parameter!</p>";

exit;

}



$numresults=mysql_query($query);

$numrows=mysql_num_rows($numresults);



if ($numrows == 0)

{

echo "<h4>Results</h4>";

echo "<p>Sorry, your search: " . $trimmed . " returned zero results</p>";

}



// next determine if s has been passed to script, if not use 0

if (empty($s))

{

$s=0;

}



// get results

$result = mysql_query($query) or die("Couldn't execute query");



if($numrows > 1){ $return = "results";}

else{ $return = "result"; }



// display what the person searched for

echo "<p>Your search for '" . $var . "" returned $numrows $return.</p>";

// begin to show results set

$count = 1 + $s ;

while ($r= mysql_fetch_array($result))

{

$id = $r["username"];

$year = $r["Bday"];

$date = $r["Nic"];

$title = $r["Land"];

$description = $r["IntName"];



$count++ ;

?>



<? echo $description ?>

Result Number: <? echo $count ?>

<?php } ?>

//By Irantha Jayasekara:irantha.86@gmail.com

</body>

</html>

Irantha Jayasekara

B.Sc(UG) in Computer Science & Technology(special)
SUSL