php - Display each color separate with values -
i having trouble in printing values 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 trying print values in table(for each color print material dimension category) output 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 using query
$query = "select a.itemnb, b.colorname, c.materialname, d.categoryname, sum(a.quantity) quantity dbo_items 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 b.colorname, c.materialname, d.categoryname, ";
i using pdo.
$q=$conn->query($query);
now can fetch values in table, not want make.
<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 print first color , material related color. having trouble there, or advice appreciated?
first remove colorname
field group by
clause in query , add column order by
means add order colorname
in query.
and change html , php code following:
<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 $tempcolor = ''; while ($r = $m->fetch()){ if($tempcolor != $r['colorname']) { ?> <tr><td colspan="4">color name: <?=$r['colorname']?></td></tr> <?php $tempcolor = $r['colorname']; } else { ?> <tr> <td><?=$r['colorname']?></td> <td><?=$r['materialname']?></td> <td><?=$r['categoryname']?></td> <td><?=$r['quantity ']?></td> <?php } } ?> </tbody> </table>
Comments
Post a Comment