Group data from different tables and join in a modal those that are from the same group

1

Good afternoon! I'm having a problem with how to think of something effective.

I have two tables: budgets and budgetlines. In the table budget_lines are some items, eg:

  • Soap
  • Inks
  • Bags
  • All of these records have the boolean id associated with the budget table, basically its function is to group all the rows of the other table. So good, everything works fine!

    Here is the question: I need to print on the screen by "Blocks", that is: take all the lines of the table budget and group with the budget table values and all these values will be printed in div1 (example) And the other rows associated with another record in the budget table will be printed in div2 (example), and so on

    The problem is that I can not think of a logic to do this, I tried a few things, but the end result has always been to print each line followed by the other. Here is the code I'm currently using:

     $sql_select = "SELECT * FROM orcamentos_linha INNER JOIN orcamentos ON (orcamentos.id = orcamentos_linha.id_orcamento AND DATE(orcamentos.data_limite) > CURDATE() ) WHERE cad = ?";  
     $stmt  = $database->prepare($sql_select);   
     $stmt->execute([$user->getCad]); 
    
        
    asked by anonymous 31.03.2017 / 18:07

    1 answer

    -1

    I do not know if I understand, but you are waiting for the query in the database to return a hierarchical data structure so that you can access the records of each budget and their respective items?

    If this is the issue, you are using the wrong feature. The database will not return data this way. Options:

    A) Return the data and group by budget. B) Use another data structure to store data in a hierarchical way, such as JSON in MongoDB or XML.

        
    31.03.2017 / 22:58