Transforming SQL results in PHP into correct value for shopping cart to
recognise
So I have quite a specific question and would appreciate if anyone is able
help at all. I'm trying to create a page that lists a users purchase
history for the past 3 months. I have simply stored the cart session data
into the table as their purchase for each transaction, which is each item
id X qty. For example, one entry may be '1,1,1,2,2,3,6,1' and another may
be '6,5,9,6,6'. I don't know how to retrieve the data from the table with
PHP in such a way that the code I have from the cart that details each of
the item ID's can recognise it. Below is the code I'm using to try and
create a value, and under that is the shopping cart page pasted in. All in
all, I would just like to be able to display all the retrieved items as a
user purchase history.
Thank you very very much.
$olddate = date("d/m/Y",strtotime("3 months ago"));
global $db;
$hist = "SELECT ORDITEMS FROM cust_orderc WHERE ORDDATE >
to_date('".$olddate."', 'dd/mm/yyyy')";
//$pastitem="";
$histitem = OCIParse($db, $hist);
OCIExecute($histitem);
while($row = OCIFetch($histitem)){
foreach ($row as $purchase){
$pastitem = $purchase;
}
}
echo "$pastitem";
if ($pastitem) {
$items = explode(',',$pastitem);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] +
1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post"
id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM Flowers WHERE FID = '.$id;
// modified by Shang
$stmt = OCIParse($db, $sql);
if(!$stmt) {
echo "An error occurred in parsing the sql string.\n";
exit;
}
OCIExecute($stmt);
while(OCIFetch($stmt)) {
$title= OCIResult($stmt,"FCOMMON");
$image = OCIResult($stmt,"FPHOTO");
$price = OCIResult($stmt,"FPRICE");
$id = OCIResult($stmt,"FID");
}
$output[] = '<tr>';
$output[] = '<td><a href="cart.php?action=delete&id='.$id.'"
class="r">Remove</a></td>';
$output[] = '<td align="center">'.$title.' <img
src="images/'.$image.'" alt="'.$title.'"
class="cart_thumb"/></td>';
$output[] = '<td align="center">Price Each<br>AU$ '.$price.'</td>';
$output[] = '<td align="center">Quantity<input type="text"
name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3"
/></td>';
$output[] = '<td align="center">Subtotal<br>AU$ '.($price *
$qty).'</td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<p>Grand total: <strong>AU$ '.$total.'</strong></p>';
$output[] = '<div><button type="submit">Update cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping cart is empty.</p>';
}
return join('',$output);
No comments:
Post a Comment