我正在尝试修复 CS-Cart 中的一些 SQL 查询,以便更好地使用它们的内置查询,以下工作以及进一步的代码循环和显示产品
$getOrder=db_get_fields("SELECT * FROM ?:orders WHERE total='".$orderSum."' AND email='".$email."' AND status IN('P','C','O') ");
$orderProducts = db_get_fields("SELECT product_id FROM cscart_order_details WHERE order_id='".$getOrder[0]."'");
但我尝试使用以下方式编写:
http://docs.cs-cart.com/4.2.x/core/db/placeholders.html
但是它只返回 1 个产品,所以我在某个地方犯了错误,但不确定是什么?有人有主意吗?我对 PHP 和 MySQL 还很陌生
$getOrder = db_get_fields("SELECT * FROM ?:orders WHERE total = ?i AND email = ?s AND status IN ('P','C','O')", $orderSum, $email);
$orderProducts = db_get_fields("SELECT product_id FROM ?:order_details WHERE order_id = ?a", $getOrder[0]);
使用循环更新并检查:
$acId = $_REQUEST['id'];
$productsGet = db_get_field("SELECT cart FROM ?:abandoned_cart WHERE user_id = ?s", $acId);
$products = unserialize($productsGet);
$cartProducts=array();
if (is_array($products) || is_object($products)){
foreach($products as $pData){
$cartProducts[]=$pData['product_id'];
}
}
if(!array_diff($cartProducts,$orderProducts)){
$products=array();
}
哦,这是输出部分,但它是新查询的问题
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="#"> <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'];
}
}
最佳答案
好的找到了问题并且相当简单
$orderProducts = db_get_fields("SELECT product_id FROM ?:order_details WHERE order_id = ?a", $getOrder[0]);
至
$orderProducts = db_get_fields("SELECT product_id FROM ?:order_details WHERE order_id = ?s", $getOrder[0]);
?a > ?s
关于PHP/MySQL - 更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35130691/