Relate category tables to subcategories

Asked

Viewed 184 times

0

I want to list two tables. For example, when you click on an item, appear all the items related to it

?>
        <?php
    include "conexao.php";


$sql = "SELECT *FROM categorias ";


$resultado = pg_query($conexao, $sql);
$linhas = pg_num_rows($resultado);


      $nome_categoria = $linhas["nome_categoria"];
            $resultado.= "<option>".$nome_categoria."</option>";
    $categoria = "<select class='select_roupas'>". $resultado."</select>";

for($i = 0; $i < $linhas; $i++)
{

$registro = pg_fetch_array($resultado, $i);

$sql1 = "SELECT * FROM subcategorias ";
$resultado1= pg_query($conexao,$sql1);
$registro1=pg_fetch_array ($resultado1)  ;  

      $nome_subcategoria = $linhas["nome_subcategoria"];
            $resultado1.= "<option>".$nome_subcategoria."</option>";
    $subcategoria = "<select class='select_roupas'>". $resultado1."</select>";
}


?>

2 answers

1

in the table subcategories you need to store the table id categories, so:

SELECT * FROM subcategorias WHERE categoria_id = $id_categoria;

this way will get all results of table subcategories where the category is "selected"

  • Um. Thank you. But still, it’s not showing any results. Nor the categories.

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.