Related tables in PHP to display data

-1

Currently I have a problem that I have not been able to solve, I must occupy a group of 3 tables in PHP that are related in hierarchy, that is, what shows the second depends on the first and what shows the third depends on the second.

Basically it's something like this Excel that I show you ...

The issue that I think is more complicated is that I am able to add as many rows as I can to each table.

The application I'm doing in PHP with mySQL, but I'm open to any recommendation that you give me

    
asked by Steven Gonzalez 17.07.2018 в 19:06
source

1 answer

0

Then there would be 3 SQL queries ...

The first to obtain what would be the categories,

The second one to get the subcategories based on the category that is passed from the first

The third to obtain the content based on the 1st and 2nd ...

It would be like this:

$sql = "select * from categorias";
...

while ( $row = fetch ) {

    echo 'categoria';

    $sql2 = "select * from sub_categorias where categoria_id = $row['categoria_id']";
    ...

    while ( $row2 = fetch ) {

        echo 'sub categoria';

        $sql3 = "select * from productos where categoria_id = $row['categoria_id'] AND sub_categoria_id = $row2['sub_categoria_id'] ";
        ...

        while ( $row3 = fetch ) {
            echo 'contenido';
        }
    }
}
    
answered by 19.07.2018 в 21:09