Forward:
I've checked through the similarly worded questions on Stack Overflow but none are specific to what I'm attempting.
What I have:
I have session data, two loops and a SQL table.
- The first loop checks for specific existing session data and uses the keys (rather than the values) of this data to determine what ids should be selected (SQL) from a table.
- The second loop outputs the SQL results row by row.
...this can also be described in a less abstract and friendlier manner:
- The first loop looks for items currently added to the shopping cart (key = product id, value = quantity) to determine what products should be listed on "Your order" page.
- The second loop list rows of data associated with each product id such as the title, description and unit cost.
What I need:
Since my session data consists of products ids (keys) and a corresponding quantity (values) I need to show the quantity as part of each outputted row.
id | title | description | unit cost | amount | subtotal
session data key | from database | from database | from database | session data value | basic PHP math
(also in database) (unit cost * amount)
My code:
The first loop to use the session data keys to query the require products:
$id_from_session = "WHERE id = '9999999999'"; //fix due to not being sure how to simuataneously incorporate "WHERE" and "OR" into query loop (only looping the "OR" condition).
foreach($_SESSION['post'] as $key=>$value)
{
$id_from_session .= "OR id ='".$key."'";
}
The second loop to output the resulting rows of the query:
foreach ( $yourorders as $yourorder )
{
?>
<?php echo $yourorder->title; ?></br>
<?php echo $yourorder->description; ?></br>
<?php echo $yourorder->value; ?></br>
<?php /* I NEED THE QUANTITY HERE */ ?></br>
<?php /* VALUE * QUANTITY HERE */ ?></br>
<?php
}
<?php /* OVERALL TOTAL OUTSIDE OF LOOP */ ?></br>
My question:
How do I incorporate the quantity from the session data loop (and the quantity * unit value) into the SQL results loop?