Hey, I am working with a database and I need to search every column's rows for the searched terms. I have a working way, but it returns duplicate values. The only way I could think of removing duplicate values was to place a while loop inside of the mysql_query(). Is that possible, and if so, how can I do that? This is the code I have so far. The query I am trying to put it in is the $results=mysql_query() one:

<?php
mysql_connect("connection", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$var=$_POST["search"];
$trimmed = trim($var);
$search_array = explode(" ",$trimmed);
if ($trimmed == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
$data=mysql_query("SELECT * FROM table");
$t=mysql_num_fields($data);

$num=1;
while($num<$t)
{
foreach ($search_array as $search)
{
$fieldname=mysql_field_name($data,$num);
$results=mysql_query("SELECT * FROM table WHERE ($fieldname) LIKE '%$search%'");
while($r=mysql_fetch_array($results))
{
$n=1;
while($n<$t)
{
$field=mysql_field_name($results,$n);
echo $r[$field];
echo "<br>";
$n=$n+1;
}
echo "<br>";
echo "<br>";
}
}
$num=$num+1;
}
?>