Ok I am having a small issue I am trying to turn this jQuery to PHP
What I need what to do is place this in a foreach function this is what I do first the jQuery code.
$.each(obj.products, function(i, obj) {
if(obj.barcode == barcode)
{
$("#showmoreinfohere").show();
$("#moremovietop").html(obj.name.toUpperCase());
$("img#selectedproduct").attr('src', ''+obj.logoURL+'');
$("span#perticket").html(obj.price);
currentproduct["barcode"] = obj.barcode;
currentproduct["priceperticket"] = obj.price;
currentproduct["cashbackperticket"] = obj.discount;
$("span#VIPCashBack").html(obj.discount);
total = obj.price * $("#qtyselect").val();
$("span#totalprice").html("$"+total);
}
});
My PHP CODE
<?php
$cartdata = $fetch->cartitems($_COOKIE["sessionkey"]);
foreach ($cartdata as $cart)
{
$product_details = $fetch->getbarcode('$cart["barcode]"');
?>
<tr>
<?php
foreach ($product_details as $product)
{
?>
<td><?php $product['name']?></td>
<td><?php $product['price']?></td>
<td><?php $cart['qty']?></td>
<td><?php $product['discount']?></td>
<?
}
?>
<?php
}
?>
the error I get is
Warning: Invalid argument supplied for foreach() in
/home/movies/public_html/tpl/cart.tpl on line 27
ISSUE from Googling this is what I am finding:
- you can do a foreach inside a foreach
-
JSON for product_details are returning the following
{ "_id": ObjectId("4f6ab67338fc5ded4f000000"), "company": "village", "logo": "http: \/\/...\/villagetop.png", "products": { "0": { "barcode": "236690091", "name": "Weekday", "logoURL": "http: \/\/...\/ticketpic1.png", "price": "12.50", "discount": "1.50" }, ... }, "store_name": "movies" }
Edit
Before attempting to find answers, it’s recommended that you add the following two lines at the top of your script:
Edit 2
From the JSON dump you should use either
$product_details->productsor$product_details['products']in yourforeachloop, depending on how you calledjson_decode().The following code:
Not likely to work, the proper code for that it:
Inside your loop:
This does not output anything, you want something like this: