好吧,我有我想這個jQuery轉向PHP
一個小問題我需要做的就是這個地方在foreach功能,這是什麼我首先執行jQuery代碼。
$.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);
}
});
我的PHP代碼
<?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
}
?>
我得到的錯誤是
警告:在 /家庭/電影/的public_html/TPL /車的foreach()提供的參數無效。第27行上的tpl
發現谷歌搜索這是我發現:
- ,你可以做一個foreach
JSON用於product_details內的foreach正在返回以下
{ "_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" }
什麼是PHP代碼?它會給你什麼錯誤?還是它根本就不起作用? – Dre
你會得到什麼錯誤? – xdazz
這不會顯示任何東西,因爲你沒有迴應任何東西 – Satya