1
good morning. I have a question that I have never come across before with php and mysql. I have the following example table in mysql:
ITEM : DEP : QTD
=============================
1 : T01 : 1000
2 : T02 : 2000
3 : T03 : 3000
4 : T01 : 4000
5 : T03 : 5000
=============================
Tendo esta tabela acima no mysql, eu preciso exibir uma página com uma
tabela HTML dessa maneira abaixo:
TABELA HTML PARA EXIBIR
================================
ITEM : T01 : T02 : T03
1 : 1000 : 0 : 0
2 : 0 : 2000 : 0
3 : 0 : 0 : 3000
4 : 4000 : 0 : 0
5 : 0 : 0 : 5000
================================
Explaining: I need to display a query that shows me in separate columns the Qtd of each deposit.
I did some research, and I don’t know how to do that, and I don’t know where to go with the search. I tried to make a select for each deposit and while inside while and failed. Some way to do this?
Below is my script, only I have no idea how to do it, who has an idea of how to do it, or a direction for me to research I will be very grateful.
<?
$sql = mysql_query ("SELECT item, dep, qtd FROM estoque ");
?>
<table>
<thead>
<tr>
<th>Item</th>
<th>T01</th>
<th>T02</th>
<th>T03</th>
</tr>
</thead>
<tbody>
<? while($r = mysql_fetch_array($sql)){ ?>
<tr>
<td><? echo $r['item']; ?></td>
<td></td>
<td></td>
</tr>
<? } ?>
</tbody>
</table>
By the way you will have to do a table pivot. Have you tried this?
– Fabricio
Pivot table, would be an auxiliary table for this case?
– Saulo
I found something like select case when then. I’m searching about this.
– Saulo
You are right, searching on pivot table, I see that this is the way. Thanks for the tip. As soon as I learn how to do it, I put it here as it was. Hug!
– Saulo