Searching mySQL databse with PHP
Posted: Tue Jul 14, 2009 2:09 pm
Hi there
I'm currently setting up a shopping website where I am using a PHP/mySQL script called affilistore (http://www.affilistore.com/)
The website will search baby products from a few different merchants and present them for the user to look at.
The script, out of the box, works quite well, however, the creators have made it so that it searches the items description. This is causing a few problems. If somebody searches for something like "baby wipes" it will show some baby wipes and also things like changing bags (as it states in the description of change bags "great for storing wipes"). This become even more of a problem when searching for "prams" as it will output raincovers, accessories for prams, anything with "pram" in the description.
The best way I can think of getting around this would be to make the script only search in the product name. However, I have no idea where to start. I was looking for some pointers, any help would be appreciated
I have uploaded the PHP include that, as far as I can tell actually searches and outputs the products. It can be found here in txt format:
http://tooseypegs.co.uk/public/products.inc.txt
I believe it's these lines that need to be changed. I have tried but then get scripting errors. (lines 43-51 of products.inc.php)
Many thanks
kie.
I'm currently setting up a shopping website where I am using a PHP/mySQL script called affilistore (http://www.affilistore.com/)
The website will search baby products from a few different merchants and present them for the user to look at.
The script, out of the box, works quite well, however, the creators have made it so that it searches the items description. This is causing a few problems. If somebody searches for something like "baby wipes" it will show some baby wipes and also things like changing bags (as it states in the description of change bags "great for storing wipes"). This become even more of a problem when searching for "prams" as it will output raincovers, accessories for prams, anything with "pram" in the description.
The best way I can think of getting around this would be to make the script only search in the product name. However, I have no idea where to start. I was looking for some pointers, any help would be appreciated
I have uploaded the PHP include that, as far as I can tell actually searches and outputs the products. It can be found here in txt format:
http://tooseypegs.co.uk/public/products.inc.txt
I believe it's these lines that need to be changed. I have tried but then get scripting errors. (lines 43-51 of products.inc.php)
Code: Select all
// output search results
$dbcondition = '';
if ($indcount == 0) {
$sql = "SELECT *, ( (1.3 * (MATCH(prodName) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) + (0.6 * (MATCH(prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE))) ) AS relevance FROM affiliSt_products1 WHERE ( MATCH(prodName,prodDescription,merchant,prodCategory,prodBrand) AGAINST (".quote_smart($pluspieces)." IN BOOLEAN MODE) ) HAVING relevance > 0 AND dbProdID != '".$pDetails['dbProdID']."' ORDER BY relevance DESC LIMIT 0, ".$maxRows_product."";
} else {
$sql = "SELECT * FROM affiliSt_products1 WHERE MATCH (prodName,prodDescription,prodBrand,prodCategory) AGAINST (".quote_smart($pluspieces).") AND dbProdID != '".$pDetails['dbProdID']."' LIMIT 0, ".$maxRows_product."";
}
$getSimilar = mysql_query($sql, $databaseConnect) or die(mysql_error());
$similar = mysql_fetch_assoc($getSimilar);kie.