Generate dynamic Mysql header

Asked

Viewed 113 times

0

I have below a problem that I am not able to solve.

How to make the header have the name of the employee and below it the revenue that was generated according to the date?

And what would an HTML table look like with these?

The first image is a simple query I created just to demonstrate the structure of my table.

The second is how I want it to stay.

@EDIT I can do something similar, but now I don’t know how to mount my HTML table. The IDS and names will be dynamic, where I will assemble according to each employee I have in my bank. I put static only as an example.

SELECT P.dt_venda as venda, 
SUM(CASE WHEN P.id_consultor = 4 THEN IR.receita_gerada_receita END) as funcionario4,
SUM(CASE WHEN P.id_consultor = 3 THEN IR.receita_gerada_receita END) as funcionario3,
SUM(CASE WHEN P.id_consultor = 2 THEN IR.receita_gerada_receita END) as funcionario2
FROM item_receitas as IR, funcionarios as F, pedidos as P
WHERE P.id_consultor = F.id
AND IR.id_pedido = P.id
GROUP BY venda, F.nome

Tabela SQL

  • 1

    gives a researched on pivot

  • @Rovannlinhalis, I’ll give a study on, thank you for the tip.

  • Okay @rLinhares, I put the code, thank you.

  • You have to create an HTML table like any other, using <table>, <th>, <tr>, <td>. Put your PHP code of what you have done so far, regarding query and data display, would help a lot.

  • My php code would only be this query, now I need the logic of how to mount the rows and columns of the table. The problem is: The name of the fields is dynamic, as I would control it to mount my table ?

No answers

Browser other questions tagged

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