Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Duplicate results from search code - why is it doing this?
Old 02-01-2010, 03:05 PM Duplicate results from search code - why is it doing this?
Novice Talker

Posts: 7
Name: Qadoshyah Fish
Trades: 0
My search code is returning duplicate results for one item searched. And it's the same exact result. I understand if a certain item is in there multiple times for whatever reason, but that's not the case. It's returning the same results - duplicates - like 10 or more times in a row. On the same page. Why is it doing this? It was not doing this before!

This is what I'm using for my search query:

Code:
$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, appr_commercial.CostValue, appr_commercial.BldgDescription, sale_parcel.SaleDate, sale_parcel.SalePrice, sale_parcel.InstrumentNumber
           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
           LEFT JOIN appr_commercial
           ON asmnt_parcel.Account=appr_commercial.Account
           LEFT JOIN sale_parcel
           ON asmnt_parcel.Account=sale_parcel.Account
             WHERE asmnt_parcel.Account = '{$search}' OR asmnt_parcel.OwnersName = '{$search}' OR asmnt_parcel.ParcelID = '{$search}' OR asmnt_legal.Legal = '{$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>Cost Value</td>
      <td align=center bgcolor=#4A6B3F>Bldg. Description</td>
      <td align=center bgcolor=#4A6B3F>Sale Date</td>
      <td align=center bgcolor=#4A6B3F>Sale Price</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>Book & Page</td>
      <td align=center bgcolor=#4A6B3F></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"];
         $cost = $r["CostValue"];
         $bldg = $r["BldgDescription"];
         $date = $r["SaleDate"];
         $pric = $r["SalePrice"];
         $sch = $r["TaxAreaCode"];
         $situ = $r["Situs"];
         $tship = $r["Township"];
         $rng = $r["Range"];
         $sct = $r["Section"];
         $inum = $r["InstrumentNumber"];
         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>$cost</td>
            <td>$bldg</td>
            <td>$date</td>
            <td>$pric</td>
            <td>$sch</td>
            <td>$situ</td>
            <td>$tship</td>
            <td>$rng</td>
            <td>$sct</td>
            <td>$inum</td>
            </tr>";
      } // end while
      
      echo "</table>";
You can see what I'm talking about at: http://www.wagonerassessor.com/searchjoin2.php. An example you can search by "730000008."

Now, I know when you search this account number, there are 4 or 5 different results that aren't duplicates. But, then those 4 or 5 results are there like 15 times or more. Why is it doing this???

Please help!

Thanks!
Qadoshyah
CGDesigns is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-01-2010, 04:18 PM Re: Duplicate results from search code - why is it doing this?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
That's because of the way you are using the JOIN.

A full join will get all the matching records from all the tables. including where rows would be duplicated.

You need to use LEFT and RIGHT joins to eliminate duplicates

http://www.w3schools.com/sql/sql_join.asp
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-01-2010, 06:20 PM Re: Duplicate results from search code - why is it doing this?
Novice Talker

Posts: 7
Name: Qadoshyah Fish
Trades: 0
Didn't think of that! I will give it a try changing the joins .

Thank you!
Qadoshyah
CGDesigns is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Duplicate results from search code - why is it doing this?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17737 seconds with 12 queries