Colonel_Popcorn
03-29-2009, 11:09 PM
Hey, I am working with a precarious situation here. I have finally gotten the code to search everything, but it returns duplicate values. I have tried using the array_unique() and just array() and even array_merge_recursive() but none of these have stopped the duplicate rows. When I use the array_unique() it will only return to me the first row and none others, or sometimes it won't return anything. Here is the code, I really hope someone can help me.
<html>
<body>
<?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");
$num_rows=mysql_num_rows($data);
$t=mysql_num_fields($data);
$row=array();
$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))
{
$row[]=array_merge($r, $row);
}
}
$num++;
}
$output=$row;
$rw=0;
while($rw<1000000000000000)
{
$col=1;
if ($output[$rw] == "")
{
}
else
{
while($col<=7)
{
echo $output[$rw][$col];
echo "<br>";
$col++;
}
?>
<img src="<?php echo $output[$rw][image];?>" />
<?php
echo "<br>";
}
$rw++;
}
echo "<br>";
echo "<br>";
?>
</body>
</html>
<html>
<body>
<?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");
$num_rows=mysql_num_rows($data);
$t=mysql_num_fields($data);
$row=array();
$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))
{
$row[]=array_merge($r, $row);
}
}
$num++;
}
$output=$row;
$rw=0;
while($rw<1000000000000000)
{
$col=1;
if ($output[$rw] == "")
{
}
else
{
while($col<=7)
{
echo $output[$rw][$col];
echo "<br>";
$col++;
}
?>
<img src="<?php echo $output[$rw][image];?>" />
<?php
echo "<br>";
}
$rw++;
}
echo "<br>";
echo "<br>";
?>
</body>
</html>