I am having problems printing values from a database.
ITEM TABLE
ITEM | COLOR | MATERIAL | DIMENSIONS | CATEGORY | QUANTITY
- 01 33 05 111 12 1000.00
- 02 33 07 125 18 200.00
- 03 33 11 156 18 254.00
- 04 56 15 25 66 113.00
- 05 66 05 11 33 521.00
I am trying to print the values in a table (for each dimension category of a color printed material) Thus, the output will be:
COLOR - > 33
MATERIAL | DIMENSION | CATEGORY | QUANTITY
05 111 12 1000.00
07 125 18 200.00
11 156 18 254.00
COLOR - > 56
MATERIAL | DIMENSION | CATEGORY | QUANTITY
15 25 66 113.00
COLOR - > 66
MATERIAL | DIMENSION | CATEGORY | QUANTITY
05 11 33 521.00
I am using a request
$query = "SELECT a.itemnb, b.colorname, c.materialname, d.categoryname, sum(a.quantity) as quantity
FROM dbo_items a
JOIN dbo_color b
ON a.color=b.colorid
JOIN dbo_material c
on a.material=c.material
JOIN dbo_category
on a.category=d.categoryid
GROUP BY b.colorname, c.materialname, d.categoryname, ";
I am using PDO.
$q=$conn->query($query);
Now I can get all the values in the table, but I really do not want this.
<table class="table table-bordered table-striped">
<thead>
<tr class="bg-primary">
<td data-field="color">COLOR</td>
<td data-field="material">MATERIAL</td>
<td data-field="dim">DIMENSIONS</td>
<td data-field="quantity">QUANTITY</td>
</tr>
</thead>
<tbody>
<?php while ($r = $m->fetch()){?>
<tr>
<td><?=$r['colorname']?></td>
<td><?=$r['materialname']?></td>
<td><?=$r['categoryname']?></td>
<td><?=$r['quantity ']?></td>
<?php } ?>
</tbody>
</table>
I want to print the first color, and then all the material related to that color. I have problems there, any help or advice is appreciated?
source
share