Ok, so I took some suggestions from here and another forum and here is my entire PHP script for the results page:
[php:1:24ecf0eed6]
<?php
$username = \"user\"; // your username
$password = \"pass\"; // your password
$hostname = \"localhost\"; // usually localhost
trim($searchterm);
if (!$searchterm)
{
echo \"You have not entered any search criteria. Please try again.\";
exit;
}
$searchterm = $_POST[\'searchterm\'];
$dbh = mysql_connect($hostname, $username, $password) // define how to connect to the database
or die(\"Unable to connect to MySQL\"); // error message if unable to connect
$selected = mysql_select_db(\"mydatabase\",$dbh) // what database to connect to
or die(\"Could not select database\"); // error message if unable to select database
$DatabaseTables=array(\"company_background\", \"mission_statement\"); // List all the tables in database
$arrwords=explode(\' \',$searchterm);
for($i=0;$i<count($arrwords);$i++)
{
for($j=0;$j<count($DatabaseTables);$j++)
{
$query=\"select * from \".$DatabaseTables[$j].\" WHERE page_content LIKE \'%\".$arrwords[$i].\"%\'\";
$result=mysql_query($query); // $result has all the matches in current table
}
}
while($row = mysql_fetch_row($result))
{
printf(\"<strong>Page ID:</strong> %s\", $row[0]);
printf(\"<p><strong>Page Title:</strong> %s\", $row[1]);
printf(\"<p><strong>Page Content:</strong> %s\", $row[2]);
}
?>[/php:1:24ecf0eed6]
Now when I enter in some text in the text area of some pages and press the search button, it just takes me to the results page and displays nothing.
If I take out the [php:1:24ecf0eed6]while($row = mysql_fetch_row($result))
{
printf(\"<strong>Page ID:</strong> %s\", $row[0]);
printf(\"<p><strong>Page Title:</strong> %s\", $row[1]);
printf(\"<p><strong>Page Content:</strong> %s\", $row[2]);
}[/php:1:24ecf0eed6] lines then I get a result saying \"resource id #5\" or #7 in some cases even though that data isn\'t even in any of my tables. Any help or suggestions would be appreciated.
Thanks