PHP / MySQL foreach无法正常工作

时间:2016-02-08 01:49:55

标签: php mysql ajax cs-cart

我是PHP / MySQL的新手,我试图修复cs-cart软件的插件一直都失败了。

有问题的PHP:

$acId = $_REQUEST['id'];

$productsGet = db_get_field("SELECT cart FROM ?:abandoned_cart WHERE user_id = ?i", $acId);
fn_print_die($productsGet);
$products = unserialize($productsGet);

$shippingCost = db_get_field("SELECT shipping FROM ?:abandoned_cart WHERE user_id = ?s", $acId);
$tax = db_get_field("SELECT tax FROM ?:abandoned_cart WHERE user_id = ?s", $acId);
$orderTotal = db_get_field("SELECT order_total FROM ?:abandoned_cart WHERE user_id = ?s", $acId);
$email = db_get_field("SELECT email FROM ?:abandoned_cart WHERE user_id = ?s", $acId);

$sum=0;
//echo $products;
if (!empty($products)) {
  foreach($products as $product){
    $text .='
      <tr>
        <td><a  href="http://'.$_SERVER['SERVER_NAME'].'?dispatch=products.view&product_id='.$product['product_id'].'"> <img title="" height="120" width="120" alt="" src="'.$product['main_pair']['detailed']['image_path'].'"></a></td>
        <td><a href="#" style=" font-weight:bold; color:#333; font-size:13px; text-decoration:none;">'.$product['product'].'</a><a href="#">&nbsp;<i></i></a><div style=" font-weight:bold; color:#333; font-size:12px; margin-top:4px; text-decoration:none;"> CODE: <span>'.$product['product_code'].'<!--product_code_update_2512012004--></span> </div></td>
        <td style=" text-align:center;"><span style=" font-weight:bold; color:#333; font-size:12px; margin-top:4px; text-decoration:none;">$</span><span style=" font-weight:bold; color:#333; font-size:12px; margin-top:4px; text-decoration:none;">'.$product['price'].'</span> </td>
        <td><div style="display: inline-block;vertical-align: top;width: 56px;"><input type="text" disabled value="'.$product['amount'].'" size="3"  style="border:1px solid #c2c9d0; box-shadow:0 1px 3px rgba(0, 0, 0, 0.1) inset; border-radius:3px; float: left;height: 33px;text-align: center;width: 36px;"></div></td>
        <td style="font-size:14px;  font-weight:bold; color:#333; text-align:center; font-size:13px; text-decoration:none;"><span>$</span><span stye=" color:#000;">'.$product['price']*$product['amount'].'</span> </td>
      </tr>';
    $sum =$sum+$product['price']*$product['amount'];
  }
}
来自fn_print_die($ productGet);

的回复
"a:1:{i:598710622;a:24:{s:10:\"product_id\";i:511;s:12:\"product_code\";s:4:\"3021\";s:7:\"product\";s:33:\"Avatar Lounger - Wildberry Deluxe\";s:6:\"amount\";i:1;s:15:\"product_options\";a:1:{i:365;s:3:\"731\";}s:5:\"price\";d:249;s:12:\"stored_price\";s:1:\"N\";s:9:\"main_pair\";a:5:{s:7:\"pair_id\";s:4:\"1027\";s:8:\"image_id\";s:1:\"0\";s:11:\"detailed_id\";s:4:\"2123\";s:8:\"position\";s:1:\"0\";s:8:\"detailed\";a:8:{s:10:\"image_path\";s:95:\"http://beanbags.ambientlounge.com/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg?t=1401991929\";s:3:\"alt\";s:0:\"\";s:7:\"image_x\";s:4:\"1500\";s:7:\"image_y\";s:4:\"1500\";s:15:\"http_image_path\";s:95:\"http://beanbags.ambientlounge.com/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg?t=1401991929\";s:16:\"https_image_path\";s:96:\"https://beanbags.ambientlounge.com/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg?t=1401991929\";s:13:\"absolute_path\";s:90:\"/home/ambcom/public_html/staging/beanbags/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg\";s:13:\"relative_path\";s:41:\"detailed/2/wildberry-deluxe-4_h85w-74.jpg\";}}s:5:\"extra\";a:2:{s:15:\"product_options\";a:1:{i:365;s:3:\"731\";}s:18:\"unlimited_download\";s:1:\"N\";}s:15:\"stored_discount\";s:1:\"N\";s:10:\"company_id\";s:1:\"1\";s:12:\"amount_total\";i:1;s:12:\"options_type\";s:1:\"P\";s:15:\"exceptions_type\";s:1:\"F\";s:15:\"modifiers_price\";d:0;s:6:\"is_edp\";s:1:\"N\";s:12:\"edp_shipping\";s:1:\"N\";s:8:\"discount\";i:0;s:10:\"promotions\";a:0:{}s:11:\"tax_summary\";a:3:{s:8:\"included\";d:22.6400000000000005684341886080801486968994140625;s:5:\"added\";i:0;s:5:\"total\";d:22.6400000000000005684341886080801486968994140625;}s:10:\"base_price\";d:249;s:12:\"category_ids\";a:1:{i:0;i:66;}s:13:\"display_price\";d:249;s:5:\"taxes\";a:1:{i:6;a:7:{s:9:\"rate_type\";s:1:\"P\";s:10:\"rate_value\";s:6:\"10.000\";s:18:\"price_includes_tax\";s:1:\"Y\";s:9:\"regnumber\";s:11:\"60499021423\";s:8:\"priority\";i:0;s:12:\"tax_subtotal\";d:22.6400000000000005684341886080801486968994140625;s:11:\"description\";s:3:\"GST\";}}}}"

以上是从函数到调试;这是数据库字段中的内容:

a:1:{i:598710622;a:24:{s:10:\"product_id\";i:511;s:12:\"product_code\";s:4:\"3021\";s:7:\"product\";s:33:\"Avatar Lounger - Wildberry Deluxe\";s:6:\"amount\";i:1;s:15:\"product_options\";a:1:{i:365;s:3:\"731\";}s:5:\"price\";d:249;s:12:\"stored_price\";s:1:\"N\";s:9:\"main_pair\";a:5:{s:7:\"pair_id\";s:4:\"1027\";s:8:\"image_id\";s:1:\"0\";s:11:\"detailed_id\";s:4:\"2123\";s:8:\"position\";s:1:\"0\";s:8:\"detailed\";a:8:{s:10:\"image_path\";s:95:\"http://beanbags.ambientlounge.com/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg?t=1401991929\";s:3:\"alt\";s:0:\"\";s:7:\"image_x\";s:4:\"1500\";s:7:\"image_y\";s:4:\"1500\";s:15:\"http_image_path\";s:95:\"http://beanbags.ambientlounge.com/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg?t=1401991929\";s:16:\"https_image_path\";s:96:\"https://beanbags.ambientlounge.com/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg?t=1401991929\";s:13:\"absolute_path\";s:90:\"/home/ambcom/public_html/staging/beanbags/images/detailed/2/wildberry-deluxe-4_h85w-74.jpg\";s:13:\"relative_path\";s:41:\"detailed/2/wildberry-deluxe-4_h85w-74.jpg\";}}s:5:\"extra\";a:2:{s:15:\"product_options\";a:1:{i:365;s:3:\"731\";}s:18:\"unlimited_download\";s:1:\"N\";}s:15:\"stored_discount\";s:1:\"N\";s:10:\"company_id\";s:1:\"1\";s:12:\"amount_total\";i:1;s:12:\"options_type\";s:1:\"P\";s:15:\"exceptions_type\";s:1:\"F\";s:15:\"modifiers_price\";d:0;s:6:\"is_edp\";s:1:\"N\";s:12:\"edp_shipping\";s:1:\"N\";s:8:\"discount\";i:0;s:10:\"promotions\";a:0:{}s:11:\"tax_summary\";a:3:{s:8:\"included\";d:22.6400000000000005684341886080801486968994140625;s:5:\"added\";i:0;s:5:\"total\";d:22.6400000000000005684341886080801486968994140625;}s:10:\"base_price\";d:249;s:12:\"category_ids\";a:1:{i:0;i:66;}s:13:\"display_price\";d:249;s:5:\"taxes\";a:1:{i:6;a:7:{s:9:\"rate_type\";s:1:\"P\";s:10:\"rate_value\";s:6:\"10.000\";s:18:\"price_includes_tax\";s:1:\"Y\";s:9:\"regnumber\";s:11:\"60499021423\";s:8:\"priority\";i:0;s:12:\"tax_subtotal\";d:22.6400000000000005684341886080801486968994140625;s:11:\"description\";s:3:\"GST\";}}}}

控制台中的PHP错误:

  

致命错误:ob_get_clean()[&lt; a href ='ref.outcontrol'&gt; ref.outcontrol&lt; / a&gt;]:无法在 /home/ambcom/public_html/staging/beanbags/app/Tygh/Ajax.php 在线 131

PHP错误日志:

  

[Mon Feb 08 01:44:59 2016] [错误] [客户端90.199.142.58] PHP致命   错误:ob_get_clean()[ref.outcontrol]:   不能在输出缓冲显示处理程序中使用输出缓冲   /home/ambcom/public_html/staging/beanbags/app/Tygh/Ajax.php上线   131,referer:/admin.php?dispatch=cart.cart_list [Mon Feb 08 01:44:59   2016] [错误] [客户端90.199.142.58] PHP致命错误:不支持   操作数类型   /home/ambcom/public_html/staging/beanbags/app/Tygh/Database.php on   第632行,参考文献:/admin.php?dispatch=cart.cart_list [2008年2月1日星期一   01:44:59 2016] [错误] [客户端90.199.142.58] PHP通知:   unserialize()[function.unserialize]:偏移时出错   20个字节中的23个   /home/ambcom/public_html/staging/beanbags/app/addons/abandoned_cart_extended/controllers/backend/ac.php   在第24行,referer:/admin.php?dispatch = cart.cart_list

我认为如果我没有弄错,控制台中的错误以及日志中的前2可以忽略,但重点是

  

注意:unserialize()[function.unserialize]:第24行/home/ambcom/public_html/staging/beanbags/app/addons/abandoned_cart_extended/controllers/backend/ac.php中偏移量为23的2060字节错误, referer:/admin.php?dispatch=cart.cart_list

这是行:

$products = unserialize($productsGet);

现在,我似乎正在从查询中拉出购物车数据。但它不仅仅是喜欢它在反序列化部分然后再循环。

从查询返回的数据与“cart”列中的数据库中的数据完全相同,所以PHP可能试图处理错误? a:1部分。

0 个答案:

没有答案