duandong7980 2012-10-19 04:26
浏览 283

while($ row = mysql_fetch_array($ result))不起作用

I'm using the below code to get some data.

    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)) {
        $data[] = array(
            $row['Qty'], 
            $row['Description'] 
        );      
    }

This is giving an empty array.

When I'm trying the $sql manually its getting the correct results.

Is anything wrong with the code above..?

SELECT CO.order_id AS TaxNo, 
DATE_FORMAT(CO.created,'%d-%m-%Y') AS InvoiceDate, 
C.company_name AS Consumer, CONCAT(C.delivery_address1, ', ', 
C.delivery_address2) AS DelAdd, 
COD.qty AS Qty, 
P.product_name AS Description, 
PP.amount AS Price, 
(COD.qty * PP.amount) AS Total, 
SUM(COD.qty * PP.amount) AS InvoiceTotal, 
CPH.discount_on_payment AS Discount, 
CPH.amount_paid AS AmountPaid, 
(SUM(COD.qty * PP.amount) - CPH.discount_on_payment - CPH.amount_paid) AS Balance,  
COUNT(COD.qty) AS TotLine 
FROM consumer_orders AS CO 
INNER JOIN consumer AS C ON CO.consumer_id = C.consumer_id 
INNER JOIN consumer_order_details AS COD ON CO.order_id = COD.order_id 
INNER JOIN product AS P ON COD.Product_id = P.product_id 
LEFT JOIN product_price AS PP ON P.product_id = PP.product_id 
LEFT JOIN tbl_customer_payment_history AS CPH 
ON CO.order_id = CPH.order_id WHERE CO.order_id = '60' 
GROUP BY CO.order_id, CO.created, C.company_name, CONCAT(C.delivery_address1, ', ', C.delivery_address2), COD.qty, P.product_name, PP.amount 
  • 写回答

6条回答 默认 最新

  • dongpenggan6812 2012-10-19 04:34
    关注

    Try this: define $data outside the loop

      $result = mysql_query($sql);
      $data = array(); // initialize/define the variable outside the loop
      while($row = mysql_fetch_array($result)) {
            $data[] = array(
                $row['Qty'], 
                $row['Description'] 
            );      
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作