This question already has an answer here:
My store table looks like this:
| strid | userid |
__________________
| 9 | 35 |
| 17 | 44 |
My products table looks like this:
| prodid | userid | strid |
___________________________
| 9 | 35 | 9 |
| 10 | 44 | 17 |
| 11 | 44 | 17 |
I want to echo a result that looks like this:
-----------------
| STORE ID: 9 |
-----------------
| PRODUCT ID: 9 |
-----------------
------------------
| STORE ID: 17 |
------------------
| PRODUCT ID: 10 |
| PRODUCT ID: 11 |
------------------
Basically I want to echo the strid column and underneath it echo all its corresponding prodid's
that link with its strid
.
The current code I have only echoes information for one store and not the other:
<?php
$sql = "SELECT strid FROM store ORDER BY strid DESC";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$strid1 = $row["strid"];
?>
<div class="spct">STRID: <?php echo $strid1; ?>
<?php
$sql = "SELECT * FROM prodtabs WHERE strid='$strid1'";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$prodid2 = $row["prodid"];
$userid2 = $row["userid"];
$strid2 = $row["strid"];
?>
<div class="spct">PRODID: <?php echo $prodid2; ?></div>
<?php } ?>
</div>
<?php } ?>
Please help me?
</div>