A
Anonymous
Guest
I have a database.
The table saves various information about the sale of products.
I need to see under every purchase date the corresponding product (-producti id - product type - price)
nrcrt | productid | product_type | purchase_date | prices
............................................................................
1 | 35 | 101 | 2020-08-24 | 128
2 | 35 | 202 | 2020-08-24 | 150
3 | 35 | 1001 | 2020-08-24 | 224
4 | 35 | 101 | 2020-09-29 | 130
5 | 35 | 202 | 2020-09-29 | 160
6 | 35 | 1001 | 2020-09-29 | 240
............................................................................
I used this query:
$productid='35';
$query_prices = $mysqli->query("SELECT * FROM purchases WHERE productid='$productid' GROUP BY purchase_date, product_type ORDER BY product_type ASC");
$query_prices_date = $mysqli->query("SELECT purchase_date FROM purchases WHERE productid='$productid' GROUP BY purchase_date ORDER BY purchase_date DESC");
while($row_prices = $query_prices->fetch_array()) {
$x=0; while ($x<1) { $row_tar_date=mysqli_fetch_array($query_prices_date,MYSQLI_ASSOC);
if (isset($row_prices_date["purchase_date"])) {
echo '<h6>Purchase date: '.$row_prices_date["purchase_date"].'</h6>'; } else { echo ''; }
$x++; }
echo '<h6>- '.$row_prices["productid"].' - '.$row_prices["product_type"].' - '.$row_prices["prices"].'</h6>';
}
The result was the display of products after the first date from the database
Purchase date: 2020-09-29
- 35 - 101 - 130
Purchase date: 2020-08-24
- 35 - 101 - 128
- 35 - 202 - 150
- 35 - 202 - 160
- 35 -1001 - 224
- 35 -1001 - 240
The result should be as follows:
Purchase date: 2020-08-24
- 35 - 101 - 128
- 35 - 202 - 150
- 35 -1001 - 224
Purchase date: 2020-09-29
- 35 - 101 - 130
- 35 - 202 - 160
- 35 -1001 - 240
The table saves various information about the sale of products.
I need to see under every purchase date the corresponding product (-producti id - product type - price)
nrcrt | productid | product_type | purchase_date | prices
............................................................................
1 | 35 | 101 | 2020-08-24 | 128
2 | 35 | 202 | 2020-08-24 | 150
3 | 35 | 1001 | 2020-08-24 | 224
4 | 35 | 101 | 2020-09-29 | 130
5 | 35 | 202 | 2020-09-29 | 160
6 | 35 | 1001 | 2020-09-29 | 240
............................................................................
I used this query:
$productid='35';
$query_prices = $mysqli->query("SELECT * FROM purchases WHERE productid='$productid' GROUP BY purchase_date, product_type ORDER BY product_type ASC");
$query_prices_date = $mysqli->query("SELECT purchase_date FROM purchases WHERE productid='$productid' GROUP BY purchase_date ORDER BY purchase_date DESC");
while($row_prices = $query_prices->fetch_array()) {
$x=0; while ($x<1) { $row_tar_date=mysqli_fetch_array($query_prices_date,MYSQLI_ASSOC);
if (isset($row_prices_date["purchase_date"])) {
echo '<h6>Purchase date: '.$row_prices_date["purchase_date"].'</h6>'; } else { echo ''; }
$x++; }
echo '<h6>- '.$row_prices["productid"].' - '.$row_prices["product_type"].' - '.$row_prices["prices"].'</h6>';
}
The result was the display of products after the first date from the database
Purchase date: 2020-09-29
- 35 - 101 - 130
Purchase date: 2020-08-24
- 35 - 101 - 128
- 35 - 202 - 150
- 35 - 202 - 160
- 35 -1001 - 224
- 35 -1001 - 240
The result should be as follows:
Purchase date: 2020-08-24
- 35 - 101 - 128
- 35 - 202 - 150
- 35 -1001 - 224
Purchase date: 2020-09-29
- 35 - 101 - 130
- 35 - 202 - 160
- 35 -1001 - 240