[英]Select products of a certain category and brand
I have a quert where i want to select all products that have the category and brand selected on url: 我有一个询问器,在这里我想选择在url上选择了类别和品牌的所有产品:
http://localhost/www.fermaster.pt/listaProdutos/category1/brand-1 http://localhost/www.fermaster.pt/listaProdutos/category1/brand-1
"SELECT prod.*
FROM produtos as prod
INNER JOIN categorias as cat
ON cat.nomeCategoria LIKE '".$categoria."'
INNER JOIN marcas as m
ON m.nomeCategoria LIKE '".$marca."'
WHERE prod.categoriaProduto = cat.ID
AND prod.marcaProduto = m.ID"
It gives me the error 它给我错误
Warning: Illegal string offset 'nomeProduto' in C:\\wamp\\www\\www.fermaster.pt\\pages\\listaProdutos.php on line 32 警告:第32行的C:\\ wamp \\ www \\ www.fermaster.pt \\ pages \\ listaProdutos.php中的字符串偏移量'nomeProduto'不合法
The full code is: 完整的代码是:
<?php
$db = new Database();
$db->connect();
if(isset($marca))
{
echo 'Produto - Categoria - Marca';
$db->sql("SELECT prod.*
FROM produtos as prod
INNER JOIN categorias as cat
ON cat.nomeCategoria LIKE '".$categoria."'
INNER JOIN marcas as m
ON m.nomeCategoria LIKE '".$marca."'
WHERE prod.categoriaProduto = cat.ID
AND prod.marcaProduto = m.ID");
}
else
{
echo 'Produto - Categoria';
$db->sql("SELECT prod.*
FROM produtos as prod
INNER JOIN categorias as cat
ON cat.nomeCategoria LIKE '".$categoria."'
WHERE prod.categoriaProduto = cat.ID");
}
$res = $db->getResult();
foreach($res as $output)
{
echo '<br />'.$output['nomeProduto'];
}
?> ?>
I think you have to escape the string first because of the /
elements. 我认为由于/
元素,您必须先转义字符串。 MySQLs QUOTE()
function is your friend here. MySQLs QUOTE()
函数是您的朋友。 Check the MySQL Manual on that topic. 查看关于该主题的MySQL手册 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.