Hello, This might be an easy solution for you guys, but I'm learning php on my own and I'm having problems with this code. Its giving me an output of what I want but I'm also getting this error "Notice: Undefined variable: construct in C:\wamp\www\search_exp\data.php on line 27" the line 27 is on the first $construct line.
Thanks
<?php
mysql_connect("localhost","root","SNIP");//
mysql_select_db("SNIP");
$product_search = mysql_real_escape_string($_POST['product_search']);
//$result = mysql_query("SELECT product FROM searchengine WHERE product='$product_search'");
//$result_num_rows = mysql_num_rows($result); //this checks for fales (0) or true (1).
if ($product_search==NULL) {
echo "Please enter an ingredient or dish"; }
else
{
echo "You searched for <b>$product_search</b><hr size='1'>";
$search_exploded = explode(" ", $product_search);
$x = 0;
foreach($search_exploded as $search_each) {
//construct query
$x++;
if ($x==1) {
$construct .= "product LIKE '%" .$search_each. "%'";}
else{
$construct .= "OR product LIKE '%" .$search_each. "%'";}
// }
//$product_search = 0;
//while ($product_search < count($search_exploded)) {
/*if ($product_search == 0) {
$construct = "product LIKE '%" . $product_search . "%'";
} else {
$construct .= "OR product LIKE '%" . $product_search . "%'";
}
$product_search++;
}*/ }
$construct = "SELECT * FROM searchengine WHERE $construct";
$run = mysql_query($construct);
$found = mysql_num_rows($run);
if ($found==0)
echo "Sorry, cannot find ingredient or dish. If you like to contribute, you can submit an ingredient or dish that you think will be useful";
else
{
echo "$found results found!<p>";
while ($runrows = mysql_fetch_assoc($run))
{
//get data
$store = $runrows['store'];
$product = $runrows['product'];
$description = $runrows['description'];
//$price = $runrows['price'];
//$saving = $runrows['saving'];
//$distance = $runrows['distance'];
echo "
<b>$store</b><br>
Product: $product<br>
Description: $description<p>";
}
}}
?>