hmmm...i think i understand what all that does...it's extremely messy from the cut and paste.
i don't quite know what to tell you that i didn't explain before...here, i'll give you the code for a very simple site search engine i recently wrote, and hope that you will be able to adapt it to suit your needs.
the search engine is fed keywords, searches all the tables in the database for those keywords, and returns all results. the only real difference between what it does and what you need is that what it looks for varies depending on what the user stuck in the $search variable via an input field. the script starts out knowing what $search is because it grabs is from the URL (www.website.org/search.php3?search=whatever+whatever)
<?php
//$plus is a space
$plus = " ";
//$search_words is an array. it is created by the php function 'split([remove all spaces from], [$search])'
$search_words = split($plus, $search);
//$search_num is how many search words there were
$search_num = count($search_words);
//$table is an array that contains all the different tables that are searched
$table = array("main","ilinks","about","fbs","awards","finder","news");
//$table_num is the number of tables in $table
$table_num = count($table);
//print to browser: Your Search Results for "whatever whatever"
printf("<h1>Your Search Results for: \"$search\"</h1>");
//begin looping through the tables
/
for ([start internal pointer at the first thing in the array]; [as long as the loop has gone through itself less times than $table_num]; [keep looping]){
/
for ($i = 0; $i < $table_num; ++$i)
{
/
start building mysql query. we'll add to $statement later, for right now it equals: SELECT tbl, page, title, description FROM [$table[loop number in array]] WHERE keywords LIKE '%[$search_words[first in array]%'
/
$statement = "SELECT tbl, page, title, description FROM $table[$i] WHERE keywords LIKE '%$search_words[0]%' ";
//if there was more than one search word (whatever+whatever instead of just whatever) add those different search words to $statement via the .= operator. $idx acts the same here as $i did above
if ($search_num > 1){
for ($idx = 1; $idx < $search_num; ++$idx){
$statement .= " OR keywords LIKE ";
$statement .= "'%$search_words[$idx]%' ";
}
}
/
do the actual search
/
//stuff for connecting to the database
$db = mysql_pconnect("servername", "user", "pass");
mysql_select_db("database", $db);
//$result is equal to the query result. a mysql query is done using $statement assembled above and $db established above
$result = @mysql_query($statement, $db);
//$num_of_rows = however many table rows were returned above in $result
$num_of_rows = mysql_num_rows($result);
//if ([more than zero rows were returned, continue]){
if($num_of_rows > 0) {
/
KILLAH, this is where the results actually get spit out to the web browser. study it.
/
//do the stuff in curly brackets once for each row returned from the database table. $row is an array containing all the different fields returned for the current row being processed by the loop, if you have 2 rows returned, it'll spit out 2 results
while ($row = mysql_fetch_row($result))
{
/*
print the following html code to browser:
<p>
<a href="../phpfile.php3/page.html>The Stuff Returned from the 'title' table column in this row </a><br>
The stuff Returned from the 'description' table column in this row<br>
<font color=#57A275>www.website.org/phpfile.php3/page.html</font>
</p>
print "<p><a href=\"../$row[0].php3/$row[1].html\">
$row[2]</a><br>$row[3]<br><font color=#57A275>www.website.org/$row[0].php3/$row[1].html</font></p>
";
//these curly brackets end all the loops that are still running, once they are done looping.
}
}
}
?>
whew! that was quite a task...i didn't have any comments in the code above until just now...in case you didn't know // and /,/ are comment indicators.
anyhow, the end result to the thing above looks almost indentical to the results you would get from searching for 'whatever' on google or altavista or lycos or something. there isn't anything for error handling, and i've still got lots of room to improve on it, but i just started learning PHP this month, and i'm happy with what it does for now.
if this still doesn't make sense, i don't think i can clarify much further, but i'll try. let me know if it does or doesn't work.
good luck
-dolphinsnot