Foreach with 2 conditions

2

I'm trying to put two conditions in the foreach, but I'm not having success. The idea is as follows: the client accesses the website at the following URL: / room / balcony and only products that have in their database in the DB the room environment and the category 'balcony' appear.

The code is the one I'm using

.htaccess

RewriteRule ^produtos/(.*)$ produtos.php?id=$1&cat=$2

Search 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 'all_products' table contains the two terms, environment and category, whereas the table 'environment_prod' only has environments and 'category_moveis' only has categories, both tables (environment and category) the structure are the same, changing only the data . As you know, foreach only has one condition, but I have already tried with & or || and none worked.

    
asked by anonymous 29.10.2017 / 00:54

1 answer

2

From what I understand:

    foreach($muda_path as $produto_link){
        $ProdID = $produto_link;
        foreach($muda_path1 as $produto_link1){
            $subcat = $produto_link1;
            $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());
        }
    }

If it does not solve your problem try to specify the question and put more data as the table structure's print + the values that will in the URL, I could not understand for sure what data will be exploded and how this SQL should return. p>     

29.10.2017 / 02:03