我正在尝试制作“相关产品”查询以搜索5个相关产品,但它会出现此错误: 错误图片:http://puu.sh/eeo5n/a845ef5ba3.png
这是我的代码
// Info current t-shirt. Normally from database
$name = "Luftrauser T-shirt";
$description = "Stylish LUFTRAUSERS T-shirt designed by Amon26.";
$relatedSearch = $name . $description;
// Query which searches for related items
$query = $db->prepare("SELECT * FROM tbl_products WHERE name, description LIKE '%:relatedSearch%'");
$query -> bindParam("relatedSearch", $relatedSearch, PDO::PARAM_STR);
if($query -> execute()) {
while($related = $query->fetch(PDO::FETCH_OBJ)) {
echo $related->title . "</br>";
}
}
为什么它不返回包含我用LIKE搜索的值的行?
答案 0 :(得分:3)
如果您希望搜索查找名称和描述并匹配EITHER
SELECT *
FROM tbl_products
WHERE description LIKE '%:relatedSearch%' OR name LIKE '%:relatedSearch%'
如果您希望搜索查找名称和描述并匹配BOTH
SELECT *
FROM tbl_products
WHERE description LIKE '%:relatedSearch%' AND name LIKE '%:relatedSearch%'