CarpeCodice
Coder
Hi!
I have this CRUD project that I am working on, a very typical one. So the main page is a COMMODITIES page where a list of commodities appears:

If you click on VIEW button next to a particular COMMODITY, it would typically show the following:

But I would like it to show something different - a list of all MARKET PRICES for the chosen COMMODITY like in the image below (this image is not filtered yet by commodity):

So, I have managed to build the page in this last image, but I have not managed to figure out the coding required to show only the market prices related to the specific commodity where I clicked the VIEW button in the first image. As a bonus, I would also like to be able to show the selected commodity in the title in this third image, something like "Market Prices for Vodka Smirnoff Red 70cl".
In MySQL I have created the relationship - see below image - I think this is created as a one-to-many, but I am not certain:

And the code of the Market Prices page follows below - any help would be greatly appreciated - thank you in advance!:
I have this CRUD project that I am working on, a very typical one. So the main page is a COMMODITIES page where a list of commodities appears:

If you click on VIEW button next to a particular COMMODITY, it would typically show the following:

But I would like it to show something different - a list of all MARKET PRICES for the chosen COMMODITY like in the image below (this image is not filtered yet by commodity):

So, I have managed to build the page in this last image, but I have not managed to figure out the coding required to show only the market prices related to the specific commodity where I clicked the VIEW button in the first image. As a bonus, I would also like to be able to show the selected commodity in the title in this third image, something like "Market Prices for Vodka Smirnoff Red 70cl".
In MySQL I have created the relationship - see below image - I think this is created as a one-to-many, but I am not certain:

And the code of the Market Prices page follows below - any help would be greatly appreciated - thank you in advance!:
Code:
<?php
session_start();
require 'dbcon.php';
?>
<?php include('includes/header.php'); ?>
<h1>Costing System</h1>
<div class="container mt-4">
<?php include('message.php'); ?>
<div class="row">
<div class="col-md-12">
<div class="card-header">
<h4>Market Prices
<a href="mp_add.php" class="btn btn-primary float-end">Add Market Price</a>
</h4>
</div>
<div class="card-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Supplier</th>
<th>Purchase Unit</th>
<th></th>
<th></th>
<th>Price</th>
<th>Price Date</th>
<th>Notes</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM marketprices";
$query_run = mysqli_query($con,$query);
if(mysqli_num_rows($query_run) > 0) {
foreach($query_run as $marketprice) {
?>
<tr>
<td><?= $marketprice['id'] ?></td>
<td><?= $marketprice['supplier'] ?></td>
<td><?= $marketprice['p_unit_primary'] ?></td>
<td><?= $marketprice['p_unit_secondary'] ?></td>
<td><?= $marketprice['p_unit_unit'] ?></td>
<td><?= $marketprice['price'] ?></td>
<td><?= $marketprice['price_date'] ?></td>
<td><?= $marketprice['notes'] ?></td>
<td>
<a href="mp_view.php?id=<?= $marketprice['id'] ?>" class="btn btn-info btn-sm">View</a>
<a href="mp_edit.php?id=<?= $marketprice['id'] ?>" class="btn btn-success btn-sm">Edit</a>
<form action="code.php" method="POST" class="d-inline">
<button type="submit" name="delete-marketprice" value="<?= $marketprice['id']; ?>" class="btn btn-danger btn-sm">Delete</button>
</form>
</td>
</tr>
<?php
}
} else {
echo "<h5> No Records Found </h5>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php include('includes/footer.php'); ?>
Last edited: