...

View Full Version : Questions on coding for a search



CGDesigns
02-04-2010, 07:24 PM
Hi all,

I'm looking at all my options when it comes to the best way to search the database with the company I am working for. Full text searching isn't working too well for everything that we need to be able to search, since it returns too wide of results. I may try to do a view, but I'm not sure yet.

I was considering doing a couple search options on a page, but I have some questions on how I would go about doing that.

I have two search functions at this link:

I want to be able to have one search option that will let people pull up account numbers, then another that will let people pull up by a name.

My question is, how do I make it so that each of those will pull the data from the right search function? Do I just duplicate my PHP code? If so, how would I tie each one into the correct search form?

Right now, I just tried to duplicate my SELECT statement, but that didn't work. I'm only able to search by the one search form and the other doesn't work.

This is the code I have at the moment, with the duplicate select statement, which I will be taking out, since obviously that isn't the way to do it ;) -


<!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_parcel.Account, asmnt_parcel.OwnersName, asmnt_parcel.ParcelID, asmnt_parcel.Township, asmnt_parcel.Range, asmnt_parcel.Section, asmnt_parcel.LotSize, asmnt_parcel.LotSizeType, asmnt_parcel.TaxAreaCode, asmnt_parcel.TotalValue, asmnt_legal.Legal, cmn_name.Address2, cmn_name.City, cmn_name.State, cmn_name.ZipCode, asmnt_situs.Situs, appr_resident.TotalArea, appr_resident.YearBuilt, appr_miscimpr.Description, appr_miscimpr.Year, appr_miscimpr.Size, appr_miscimpr.Value, sale_parcel.SaleDate
FROM asmnt_parcel
INNER JOIN asmnt_legal
ON asmnt_parcel.Account=asmnt_legal.Account
INNER JOIN cmn_name
ON asmnt_parcel.OwnersName=cmn_name.OwnersName
INNER JOIN asmnt_situs
ON asmnt_parcel.Account=asmnt_situs.Account
INNER JOIN appr_resident
ON asmnt_parcel.Account=appr_resident.Account
INNER JOIN appr_miscimpr
ON asmnt_parcel.Account=appr_miscimpr.Account
INNER JOIN sale_parcel
ON asmnt_parcel.Account=sale_parcel.Account
WHERE asmnt_parcel.Account LIKE '{$search}'
ORDER BY asmnt_parcel.Account ASC";
"SELECT asmnt_parcel.Account, asmnt_parcel.OwnersName, asmnt_parcel.ParcelID, asmnt_parcel.Township, asmnt_parcel.Range, asmnt_parcel.Section, asmnt_parcel.LotSize, asmnt_parcel.LotSizeType, asmnt_parcel.TaxAreaCode, asmnt_parcel.TotalValue, asmnt_legal.Legal, cmn_name.Address2, cmn_name.City, cmn_name.State, cmn_name.ZipCode, asmnt_situs.Situs, appr_resident.TotalArea, appr_resident.YearBuilt, appr_miscimpr.Description, appr_miscimpr.Year, appr_miscimpr.Size, appr_miscimpr.Value, sale_parcel.SaleDate
FROM asmnt_parcel
INNER JOIN asmnt_legal
ON asmnt_parcel.Account=asmnt_legal.Account
INNER JOIN cmn_name
ON asmnt_parcel.OwnersName=cmn_name.OwnersName
INNER JOIN asmnt_situs
ON asmnt_parcel.Account=asmnt_situs.Account
INNER JOIN appr_resident
ON asmnt_parcel.Account=appr_resident.Account
INNER JOIN appr_miscimpr
ON asmnt_parcel.Account=appr_miscimpr.Account
INNER JOIN sale_parcel
ON asmnt_parcel.Account=sale_parcel.Account
WHERE asmnt_parcel.OwnersName LIKE '{$search}'
ORDER BY asmnt_parcel.Account ASC";
$result = mysql_query($query, $con) or die(mysql_error().": $query");

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</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>Legal</td>
<td align=center bgcolor=#4A6B3F>Parcel ID</td>
<td align=center bgcolor=#4A6B3F>Property Size</td>
<td align=center bgcolor=#4A6B3F>Type</td>
<td align=center bgcolor=#4A6B3F>Total Sq. Ft</td>
<td align=center bgcolor=#4A6B3F>Est. Year Built</td>
<td align=center bgcolor=#4A6B3F>Total Value</td>
<td align=center bgcolor=#4A6B3F>Impr. Description</td>
<td align=center bgcolor=#4A6B3F>Impr. Year</td>
<td align=center bgcolor=#4A6B3F>Impr. Size</td>
<td align=center bgcolor=#4A6B3F>Impr. Value</td>
<td align=center bgcolor=#4A6B3F>School District</td>
<td align=center bgcolor=#4A6B3F>Situs</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>Sale Date</td>
</tr>";

while ($r = mysql_fetch_array($result))
{ // Begin while
$act = $r["Account"];
$nme = $r["OwnersName"];
$add = $r["Address2"];
$city = $r["City"];
$ste = $r["State"];
$zip = $r["ZipCode"];
$legal = $r["Legal"];
$pid = $r["ParcelID"];
$size = $r["LotSize"];
$type = $r["LotSizeType"];
$sqft = $r["TotalArea"];
$built = $r["YearBuilt"];
$valu = $r["TotalValue"];
$impr = $r["Description"];
$iyr = $r["Year"];
$isze = $r["Size"];
$ivlu = $r["Value"];
$sch = $r["TaxAreaCode"];
$sit = $r["Situs"];
$tship = $r["Township"];
$rng = $r["Range"];
$sctn = $r["Section"];
$date = $r["SaleDate"];
echo "<tr>
<td>$act</td>
<td>$nme</td>
<td>$add</td>
<td>$city</td>
<td>$ste</td>
<td>$zip</td>
<td>$legal</td>
<td>$pid</td>
<td>$size</td>
<td>$type</td>
<td>$sqft</td>
<td>$built</td>
<td>$valu</td>
<td>$impr</td>
<td>$iyr</td>
<td>$isze</td>
<td>$ivlu</td>
<td>$sch</td>
<td>$sit</td>
<td>$tship</td>
<td>$rng</td>
<td>$sctn</td>
<td>$date</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">
<p></p>
</div>
<h1></h1>
<h1></h1>
<h1>Search Records</h1>
<form method="post" action="searchjoin3.php">
<table width=90% align=center>
<tr><td>Search by Account Number:</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 method="post" action="searchjoin3.php">
<table width=90% align=center>
<tr><td>Search by Name (ex. Smith, Joe):</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>



Do I need a couple of these -
$search = $_POST['search'];? Just named different?

Thanks for any & all help!! I'm somewhat new to PHP coding and all, so sorry if this is a stupid question!

Qadoshyah



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum