Tackle this PHP array code if you feel brave - it's complex, unorganized, and ineffecient.
I'm trying to compare the search query with a field "keywords" in the database for all the rows in the table. If any keywords match any words in the typed query, it displays a result.
Here's the code....
It just runs for (I clocked it), 18 seconds, then stops and doesn't display ANYTHING.
Thanks for ANY help, there's GOT to be a better way to do this.
-Matt
I'm trying to compare the search query with a field "keywords" in the database for all the rows in the table. If any keywords match any words in the typed query, it displays a result.
Here's the code....
PHP:
//Split the query into an array.
$i = 0;
$qq = explode(" ", $q);
$curid = 0;
$i3 = -1;
while ($i <= count($qq))
{
$curid ++;
if (mysql_num_rows(mysql_query("SELECT * FROM websites WHERE id='$curid'")) == 0)
{
$node = 0;
$e = mysql_query("SELECT * FROM websites");
while ($rr = mysql_fetch_array($e))
{
$keyss = stripslashes($rr['keywords']);
$keys = explode(" ", $keyss);
$title = stripslashes($rr['name']);
$url = stripslashes($rr['url']);
$des = stripslashes($rr['des']);
}
$ii = 0;
while ($ii <= count($qq))
{
$keys[$ii] = strtolower($keys[$ii]);
$qq[$ii] = strtolower($qq[$ii]);
if (in_array($qq[$ii], $keys))
{
$node ++;
//Add this to our array so we don't list it again.
$i3 ++;
$listed[$i3] = $url;
$i4 = 0;
while ($i4 <= count($listed))
{
if ($listed[$i4] == $url)
{
$dontshow = true;
}
else
{
$dontshow = false;
}
}
if (!$dontshow)
{
?>
<big><a href="<?php echo($u) ?>"><b><?php echo($title) ?></b></a></big><br>
<?php echo($des) ?><br>
<font color="darkgreen"><?php echo(strtolower($url)); ?></font>
<br><br>
<?php
}
}
$ii ++;
}
$i ++;
}
}
if (!$node || $node == 0 || $node == "0")
{
echo("No locally-submitted website content results were found.");
}
It just runs for (I clocked it), 18 seconds, then stops and doesn't display ANYTHING.
Thanks for ANY help, there's GOT to be a better way to do this.
-Matt






