Limiting post sql results
<p>Im building a search engine from  scratch that scan many different table in multiple dbs.  it looks only in specific columns for the data that is being searched.  I have it setup with an explode on in case they search for multiple words and use a foreach statement to search the tables.  However im having trouble structuring the code base for the limiting the results to show only one of each unique result.  For example if I search "Joe Schmoe" my code will search  for first = joe and last = schmoe.  It will display a result for each result.  I want it to only display one result for two search.</p>

<pre><code>&lt;?php

echo "&lt;h1&gt;Search Results&lt;/h1&gt;";

echo "&lt;table style='width: 100%;'&gt;";

$a = $_GET["q"];

$b = explode(" ", $a);

include 'db_connect3.php';

mysql_select_db("db440035579", $con);

foreach($b as $c){
$sql="SELECT * FROM users WHERE first LIKE '%$c%' || last LIKE '%$c%'";

$result = mysql_query($sql);

while($row = mysql_fetch_array($result))
  {
  echo "&lt;a href='applications.php?act=search&amp;uid=$row[7]'&gt;$row[5], $row[4]&lt;/a&gt;";
  }
}


mysql_close($con);
?&gt;
</code></pre>
