doubengshao8872 2016-02-01 12:35
浏览 58
已采纳

PHP / MySQL - 更新查询

I am trying to fix up some SQL queries in CS-Cart so uses their built in queries better, the following works and further in code loops through and displays products

$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]."'");

But i have tried to write using:

http://docs.cs-cart.com/4.2.x/core/db/placeholders.html

However it only ever returns 1 product so im making a mistake somewhere and no sure what? anyone have any ideas? im rather new to PHP and 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]);

UPDATE with loop and check:

$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();
}

oh here is the output part but its the issue with the new queries

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'];
  }
}
  • 写回答

2条回答 默认 最新

  • doufan3408 2016-02-01 12:48
    关注

    Ok found the issue and was rather simple

    $orderProducts = db_get_fields("SELECT product_id FROM ?:order_details WHERE order_id = ?a", $getOrder[0]);
    

    to

    $orderProducts = db_get_fields("SELECT product_id FROM ?:order_details WHERE order_id = ?s", $getOrder[0]);
    

    ?a > ?s

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思