2
I’m trying to put two conditions on the foreach, but I’m not succeeding. The idea is as follows: the client accesses the site in the following URL: /room/balcony and appears only products that have in their register in DB the environment 'room' and the category 'countertop'.
The code is the one I’m using
.htaccess
RewriteRule ^produtos/(.*)$ produtos.php?id=$1&cat=$2
Consultation page
$ProdAmb= $_GET['id'];
$ProdCat= $_GET['cat'];
$muda_path = explode('/', $ProdAmb);
$muda_path1 = explode('/', $ProdCat);
foreach($muda_path as $produto_link){
$ProdID = $produto_link;
$subcat = $sub;
$prod_select_categoria = "SELECT * FROM todos_produtos INNER JOIN ambiente_moveis ON ambiente_moveis.nome = todos_produtos.ambiente_prod INNER JOIN categorias_moveis ON categorias_moveis.nome = todos_produtos.categoria_prod WHERE categorias_moveis.link_cat='$subcat' OR ambiente_moveis.link_cat='$ProdID'";
$query = @mysql_query($prod_select_categoria) or die (mysql_error());
}
The table 'all products' contains the two terms, environment and category, while the table 'ambiente_prod' only has environments and 'categoria_moveis' only has categories, both tables(environment and category) the structure is equal, changing only the data. As you can see, the foreach has only one condition, but I’ve tried it with && or || and none worked.
Dude, exactly. But I’m having trouble with . htaccess right now. He is not able to return me the first variable of the url, only the 2nd is returning me.
– Thomas Franklin
Try it like this: Rewriterule (.*)$ products.php? id=$1&cat=$2 [L]
– Guilherme Biancardi