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

Asked

Viewed 44 times

1

Good afternoon! I’m having a problem on how to think of something effective.

I have two tables: budget and budget:

  1. Soap
  2. Inks
  3. Bags

All these records have the id_orcamento associated to the table orcamento, basically its function is to group all the rows of the other table. So far so good, everything works correctly!

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

The problem is that I’m not being able to 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. Follow the code I currently use:

 $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]); 

1 answer

-1

I’m not sure I understand, but you’re waiting for the query in the database to return a hierarchical data structure so that you can access the records of each budget and its respective items?

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

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

Browser other questions tagged

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