MySQL Search Description
A simple search of a mysql database. TutorialThe example below shows you how to search "-table-" for any matching entries in the "-title-" and "-info-" columns. Replace these with your own names. The results are then displayed in a table.
The Form:
<form action="searchresults.php" method=post>
<input type="text" name="search">
<input type=submit value="Search" name=search>
The Results:
<?php
$result = mysql_query("SELECT id,title FROM -table- WHERE `-title-` LIKE '%".$search."%' OR `-info-` LIKE '%".$search."%' order by id desc");
echo'<table width=100% cellspacing=0 cellpadding=4 id=content bgcolor=white>
<tr><td id=heading colspan=3>Search Results - '.$search.'</td></tr>';
$row_count = 0;
while($r=mysql_fetch_array($result))
{
$id=$r["id"];
$title=$r["title"];
echo "<tr><td><a href=\"show.php?postid=$id\">$title</a></td></tr>";
$row_count++;
}
echo "</table>";
?>
|