Hi,
I’ve been buckling down and teaching myself PHP for about a week now and am attempting to make a search script.
Rather then try to explain myself and take the chance of losing, here is main idea I have come up with so far
[code=php]if ($search) {
$srch = ‘%’.$search.’%’;
//select db code here
$query = “SELECT * FROM Product, Picture WHERE Product.Title LIKE ‘$srch’ AND Product.ProductID = Picture.EntityID ORDER BY LastModifiedDateTime ASC”;
$num_row_query = //num rows
$row_query = //fetch assoc
} do {
//exit php and do output xhtml
} while ();
}
This part works just fine, problem is that it returns too many results. I need to be able to turn products on and off. Because of this I have another table which says whether or not the Product is Enabled. So, if the search does return results, before output it needs to check that CategoryProduct.Enabled = 1.
I was able to do this successfully when a user chooses the category from a menu with this code(it returns all the products in the category chosen, but first checks CategoryProduct to see if the Product is enabled):
[code=php]
<?php
//is product Enabled
//select db
$query_productEnabled = sprintf(“SELECT * FROM CategoryProduct WHERE CategoryID = %s AND ENABLED = 1 ORDER BY CategoryProduct.LastModifiedDateTime ASC”, $colname_category);
$productEnabled = mysql_query($query_productEnabled);
$row_productEnabled = mysql_fetch_assoc($productEnabled);
$numRow_productEnabled = mysql_num_rows($productEnabled);
?>
<?php if ($numRow_productEnabled >= 1) {
do {
$enabled = $row_productEnabled [‘ProductID’];
$query_product = “SELECT * FROM Product, Picture WHERE Product.ProductID = ‘$enabled’ AND Product.ProductID = Picture.EntityID”;
$product = mysql_query($query_product);
$row_product = mysql_fetch_assoc($product);
$numRow_product = mysql_num_rows($product);
}
//html
} while ($row_productEnabled = mysql_fetch_assoc($productEnabled));
}
else
{
// html
}
?>
I feel like a j-a for being able to get it to work here, but not as a result of the search.
I tried using the same concept, but have been obviously unsuccessful.
I hope I have explained my problem thoroughly enough.
Thanks
Chris