I have a requirement to dynamically create HTML pages based on individual result sets from a mysql database. For example when the page is loaded a set of results should be generated for the query "architectural lighting" and then a file created called "architectural lighting.htm" into which the results for this query will be placed. The foreach loop should then do the same thing for "ceiling lighting" and "commercial lighting".
All this works fine except for the following.
"architectural lighting.htm" has the correct results
"ceiling lighting.htm should have just the results for "ceiling lighting" but also contains the results for "architectural lighting"
"commercial lighting.htm should have just the results for "commercial lighting" but also contains the results for "architectural lighting" and "ceiling lighting"
Here is a simplified version of my script. Please could anyone tell me why this happening and how to correct it?
<?
//Database Configs etc
require('../configure.inc');
//Put search terms in an array
$searchterms=array('architectural lighting','ceiling lighting','commercial lighting');
//Loop through each search term to produce a set of results for each search term
foreach($searchterms as $Keyword){
$query = mysql_query("SELECT * FROM $db_table WHERE act_ivities LIKE '%$Keyword%' ",$conn);
//Create a result set specific to each search term
while ($row = mysql_fetch_array($query)){
$Company_Name = $row['Company_Name'];
$Web_Site = $row['Web_Site'];
$act_ivities = $row['act_ivities'];
//Concat results into a string called "$message"
$message .= "$Company_Name<br>$Web_Site<br>$activities";
}
//Create an HTML page for each search term
$fn = fopen("../productsearches/$Keyword.htm","w");
fwrite($fn,"<html><head><body><? echo $message; ?></body></html>");
//Close While loop
}
//Close foreach loop
}
?>
Thank you
Rob