I have a search script, but I'm not sure if it's working too well, so I thought I'd also see if there is a better search script out there if I can't figure out the problem with my current script.
I need a search code that I can join in multiple tables from my database, and the results will return in a table type of structure. It's gotta be a pretty simple code .
Please post your code and any notes on how you'd like to improve it.
The code I have right now is:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<?php
$dbHost = '********';
$dbUser = '**********';
$dbPass = '*********';
$dbDatabase = '***********';
$search = $_POST['search'];
if ($search) // perform search only if a string was entered.
{
$con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error());
mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
$query = "SELECT asmnt_legal.Account, asmnt_legal.Legal, cmn_name.OwnersName, cmn_name.Address1, cmn_name.Address2, cmn_name.City, cmn_name.State, cmn_name.ZipCode, asmnt_parcel.ParcelID, asmnt_parcel.LotSize, asmnt_parcel.LotSizeType, asmnt_parcel.Township, asmnt_parcel.Range, asmnt_parcel.Section, asmnt_parcel.Quarter, asmnt_situs.Situs, appr_agland.Acres,
LEFT JOIN cmn_name ON asmnt_legal.KeyID=cmn_name.KeyID
LEFT JOIN asmnt_parcel ON asmnt_legal.Account=asmnt_parcel.KeyID
LEFT JOIN asmnt_situs ON asmnt_legal.Account=asmnt_situs.KeyID
LEFT JOIN appr_agland ON asmnt_legal.Account=appr_agland.KeyID
WHERE asmnt_legal.Account = '{$search}' OR cmn_name.OwnersName = '{$search}' OR cmn_name.Address2 = '{$search}' OR asmnt_parcel.ParcelID = '{$search}' OR asmnt_situs.Situs = '{$search}' OR asmnt_parcel.Township = '{$search}' OR asmnt_parcel.Range = '{$search}' OR asmnt_parcel.Section = '{$search}' OR asmnt_parcel.Quarter = '{$search}'
ORDER BY asmnt_legal.Account ASC, asmnt_legal.Legal ASC";
$result = mysql_query($query, $con);
if ($result)
{
echo "Results:<br><br>";
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#4A6B3F>Account</td>
<td align=center bgcolor=#4A6B3F>Owners Name</td>
<td align=center bgcolor=#4A6B3F>Address 1</td>
<td align=center bgcolor=#4A6B3F>Address 2</td>
<td align=center bgcolor=#4A6B3F>City</td>
<td align=center bgcolor=#4A6B3F>State</td>
<td align=center bgcolor=#4A6B3F>Zip Code</td>
<td align=center bgcolor=#4A6B3F>Parcel</td>
<td align=center bgcolor=#4A6B3F>Legal</td>
<td align=center bgcolor=#4A6B3F>Situs</td>
<td align=center bgcolor=#4A6B3F>Size</td>
<td align=center bgcolor=#4A6B3F>Type</td>
<td align=center bgcolor=#4A6B3F>Township</td>
<td align=center bgcolor=#4A6B3F>Range</td>
<td align=center bgcolor=#4A6B3F>Section</td>
<td align=center bgcolor=#4A6B3F>Quarter</td>
</tr>";
while ($r = mysql_fetch_array($result))
{ // Begin while
$act = $r["Account"];
$name = $r["OwnersName"];
$add1 = $r["Address1"];
$add2 = $r["Address2"];
$city = $r["City"];
$state = $r["State"];
$zip = $r["ZipCode"];
$parcel = $r["ParcelID"];
$legal = $r["Legal"];
$situs = $r["Situs"];
$lot1 = $r["LotSize"];
$acres = $r["Acres"];
$twn = $r["Township"];
$range = $r["Range"];
$sec = $r["Section"];
$quart = $r["Quarter"];
echo "<tr>
<td>$act</td>
<td>$name</td>
<td>$add1</td>
<td>$add2</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
<td>$parcel</td>
<td>$legal</td>
<td>$situs</td>
<td>$lot1</td>
<td>$acres</td>
<td>$twn</td>
<td>$range</td>
<td>$sec</td>
<td>$quart</td>
</tr>";
} // end while
echo "</table>";
}
else
{
echo "Sorry, please try your search again.";
}
}
else
{
echo "Start your search";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Searching Another Test</title>
</head>
<body bgcolor="#bba86d">
<div align="center">
</div>
<h1></h1>
<h1></h1>
<h1>Search Records</h1>
<form method="post" action="searchjoin.php">
<table width=90% align=center>
<tr><td>Search:</td><td><input type=text name='search' size=60 maxlength=255></td></tr>
<td></td>
<td><input type=submit value="Search Records"></td>
</tr>
</table>
</form>
<p></p>
<p></p>
</body>
</html>
I'm having some troubles with the code at the moment (not sure why, but it may be the host's end).
I want something similar to this. The results need to return in a table like setting with rows, if that makes sense. And, it needs to be easily searched. Other than that, I'm not too picky!