MYSQL从产品表中选择使用过滤器存储在单独的表中

时间:2017-02-03 15:15:15

标签: php mysql database filter

我有一个包含两个重要表的数据库。一张表包含我们的整个产品目录。另一个是从后端面板中选择用于搜索的过滤器列表。由于某种原因,这在执行时显示空白屏幕。我很确定我是愚蠢的,并且错过了一些愚蠢的东西。

MYSQL日志显示

SELECT * FROM product_list WHERE product_list.PRODUCT_NAME IN ('\'product1\' OR \'product2\' //etcetc

有没有人有任何想法?我的脚本如下:

echo "<table class='inventorydata'><tr><td>SKU</td><td></td><td>Title</td><td>Quanitity</td></tr><tr><td colspan='4'></td></tr>";
//table header

$filterproducts = $dbh->prepare("SELECT * FROM table_filter_selection ORDER BY filter ASC");
$filterproducts->execute();
$filterselect = $filterproducts->fetchAll();
//select all set filters from the table

$filteroptions = "'";
foreach($filterselect as $filterRow){
$filteroptions .= $filterRow['filter'] . "' OR '";
}
//set filters in to a string

$truesearch = $dbh->prepare("SELECT * FROM product_list WHERE product_list.PRODUCT_NAME IN (:filterchoice)");
$truesearch->bindParam(":filterchoice", $filteroptions, PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$truesearch->execute();
//use filters set as parameters for searching through products

foreach($truesearch as $rows){
echo "<tr><td>" . $rows['SKU'] ."<td/><td>". $rows['PRODUCT_NAME'] ."</td><td>". $rows['QTY'] . "</td></tr>";
}
//display products

echo "</table>";

1 个答案:

答案 0 :(得分:0)

我设法通过循环每个过滤器并在每个循环打开一个连接来解决这个问题。不是最漂亮的但它现在会做的。谢谢你的帮助。