I have a search script that retrieves an integer from one table and uses it to search through the IDs of a 2nd table. My issue is if the integer in Table1 appears more then once, I get duplicate results when querying Table2.

Does anyone know a way to use SQL or PHP so that if a row is already displayed it will skip it? Thanks

My code is rather convuleted but here it is if it helps:

```
//TV FILTERS
$sql = 'SELECT * FROM `table1`';
$where = array();
if ($searchlocation !== 'Any') $where[] = '`value` LIKE "%'.$searchlocation.'%"';
if ($searchmake !== 'Any')  $where[] = '`value` LIKE "%'.$searchmake.'%"';
if ($searchtype !== 'Any') $where[] = '`value` LIKE "%'.$searchtype.'%"';
if (count($where) > 0) {
  $sql .= ' WHERE '.implode(' OR ', $where);
} else {
  // Error out; must specify at least one!
}

$tvqresult = mysql_query($sql);
$num_rowstvq = mysql_num_rows($tvqresult);
while ($rowtvq = mysql_fetch_array($tvqresult)) {
$contid =  $rowtvq['contentid'];

//MAIN QUERY
$mainsql = 'SELECT * FROM `table2` WHERE `content` LIKE "%' . $searchterm . '%" AND `id` = ' . $rowtvq['contentid'] . '  AND `template` = 12';

$resultmain = mysql_query($mainsql);

$num_rowsmain = mysql_num_rows($resultmain);
if (!$resultmain) {
continue;
}

else {
while ($row = mysql_fetch_array($resultmain )) {
  echo "[!Ditto? &parents=`134` &documents=" . $row['id'] . "&tpl=`usedtempchunk`!]";
}//END MAIN LOOP

}//END MAIN ELSE

}//END TV WHILE LOOP

```