本文介绍了逻辑错误显示MySQL表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的电子商务应用商店称为学分(预付款),其中,客户可以兑换商店信用,如果他有他的帐户的功能。

I am having the feature in my e-commerce application called store credits (advance payment) wherein the customer can redeem the store credits if he has in his account.

一切工作正常到这里。

我要的是,我想在客户的我的帐户详细资料,以显示这样的数据:

What I want is that I want to display the data like this in the customer's My Account Details:

SC_OC      S_OC    SC_Amount    SC_Alloted    SC_Used    SC_Balance

ORD-0001    --        1000          1100          0          1100
  --      ORD-0001     --            --         300           800

SC_OC = Store_Credit_Order_ code

SC_OC = Store_Credit_Order_Code

S_OC = Store_Order_ code

S_OC = Store_Order_Code

每当顾客购买店里的学分,如果 SC_Alloted 0 那么商店信用将更新它通过添加它。因此,这将是这样的:

Whenever the customer purchase the store credits, if the SC_Alloted is not 0 then the store credit will update it by adding it. So it will be like this:

SC_OC      S_OC    SC_Amount    SC_Alloted  SC_Curent    SC_Used    SC_Balance

ORD-0001    --        1000        1100        1100          0          1100
  --      ORD-0001     --          --         1100        300           800
ORD-0002    --        2500        2800        3600          0          3600

S_OC SC_Used 数据从订单接表和其余的细节是从 store_credits_orders 表来了。

The S_OC and SC_Used data is coming from the orders table and the rest of the details are coming from store_credits_orders table.

我所得到的是:

SC_OC      S_OC    SC_Amount    SC_Alloted  SC_Curent    SC_Used    SC_Balance

ORD-0001  ORD-0001    1000        1100        1100          0          1100
ORD-0001  ORD-0001    1000        1100        1100        300           800
ORD-0002  ORD-0001    2500        2800        3600          0          3600

下面是我曾尝试PHP code:

Here's the PHP code that I have tried:

<?php
$table = '';
$queryToGetStoreCredit = "SELECT * FROM
                            store_credits_orders sco,
                            orders ord
                                WHERE
                                    sco.SCO_CustEmailAdd = '".$_SESSION["Customer"]["email"]."'
                                        AND
                                    ord.CustEmailAdd = '".$_SESSION["Customer"]["email"]."'
                                        AND
                                    ord.CustEmailAdd = sco.SCO_CustEmailAdd";
$validate->Query($queryToGetStoreCredit);
if ($validate->NumRows() >= 1) {
    while ($rows_sco = $validate->FetchAllDatas()) {
        $i = 0;
        $table .= '<tr>';
        $table .= '<td>'.$rows_sco["SCO_OrderCode"].'</td>';
        $table .= '<td>'.$rows_sco["OrderCode"].'</td>';
        $table .= '<td>'.$rows_sco["SCO_OrderDate"].'</td>';
        $table .= '<td>'.$rows_sco["SCO_Purchase_Amount"].'</td>';
        $table .= '<td>'.$rows_sco["SCO_Credit_Alloted"].'</td>';
        $table .= '<td>'.$rows_sco["AppliedCredits"].'</td>';
        $table .= '<td>'.$rows_sco["SCO_Credit_Alloted"].'</td>';
        $table .= '</tr>';

    }
}
?>

我如何做到这一点?

How do I achieve that ?

任何帮助是非常AP preciated。

Any help is highly appreciated.

更新1:

RST的回答后,我得到以下的输出:

After RST's answer, I get the following output:

SC_OC      S_OC    SC_Amount    SC_Alloted  SC_Curent    SC_Used    SC_Balance

ORD-0001    --       1000          1100        1100          0          1100
ORD-0001    --       1000          1100        1100        300           800
ORD-0002    --       2500          2800        3600          0          3600

更新2:

我莫名其妙地试图得到所需的输出。但我无法得到超过1的结果,这意味着,如果有超过1个订单 store_credits_orders ,我只得到了第一个结果,而不是别人。这里的code:

I have somehow tried to get the desired output. But I cannot get more than 1 result, meaning, if there are more than 1 orders in store_credits_orders, I get only the 1st result and not others. Here's the code:

<?php
$queryToGetStoreCredit = "SELECT * FROM store_credits_orders WHERE SCO_CustEmailAdd = '".$_SESSION["Customer"]["email"]."'";
$validate->Query($queryToGetStoreCredit);
if ($validate->NumRows() >= 1) {
    while ($rows_sco = $validate->FetchAllDatas()) {
        $used = $i = 0;
        $table .= '<tr>';
        $table .= '<td>'.$rows_sco["SCO_OrderCode"].'</td>';
        $table .= '<td>--</td>';
        $table .= '<td>'.$rows_sco["SCO_OrderDate"].'</td>';
        $table .= '<td>'.$rows_sco["SCO_Purchase_Amount"].'</td>';
        $table .= '<td>'.$rows_sco["SCO_Credit_Alloted"].'</td>';
        $table .= '<td>'.$used.'</td>';
        $table .= '<td>'.( $rows_sco["SCO_Credit_Alloted"] - $used ).'</td>';
        $table .= '</tr>';

        $queryToGetOrder = "SELECT * FROM orders WHERE CustEmailAdd = '".$rows_sco["SCO_CustEmailAdd"]."'";
        $validate->Query($queryToGetOrder);
        while ($row = $validate->FetchAllDatas()) {
            $table .= '<tr>';
            $table .= '<td>--</td>';
            $table .= '<td>'.$row["OrderCode"].'</td>';
            $table .= '<td>--</td>';
            $table .= '<td>--</td>';
            $table .= '<td>--</td>';
            $table .= '<td>'.$row["AppliedCredits"].'</td>';
            $table .= '<td>'.($rows_sco["SCO_Credit_Alloted"] - $row["AppliedCredits"]).'</td>';
            $table .= '</tr>';
        }
    }
}
?>

更新3:

RST的评论后,使用的print_r() $ rows_sco ,我得到以下数组结果:

After RST's comment, using print_r() on $rows_sco, I get the following array result:

Array
(
    [SCO_Id] => 1
    [SCO_OrderCode] => ORD-000001
    [SCO_CustEmailAdd] => harishmdesai@yahoo.com
    [SCO_Purchase_Amount] => 1
    [SCO_Credit_Alloted] => 100
    [SCO_OrderDate] => 2015-03-19 16:45:19
    [SCO_OrderIP] => 115.97.1.132
    [OrderId] => 1
    [OrderCode] => ORD-000001
    [CustEmailAdd] => harishmdesai@yahoo.com
    [CustDelAddId] => 1
    [ProdCode] => PK-0002-0004
    [Quantity] => 1
    [PaytMethod] => 2
    [ShippingCharges] => 1
    [TaxedAmount] => 1
    [AppliedCredits] => 10
    [PayableAmount] => 2
    [OrderDate] => 2015-03-19 16:53:46
    [OrderModified] => 0000-00-00 00:00:00
    [OrderStatus] => In Process
    [OrderIPAddress] => 115.97.1.132
)
Array
(
    [SCO_Id] => 2
    [SCO_OrderCode] => ORD-000002
    [SCO_CustEmailAdd] => harishmdesai@yahoo.com
    [SCO_Purchase_Amount] => 1
    [SCO_Credit_Alloted] => 100
    [SCO_OrderDate] => 2015-03-19 17:01:25
    [SCO_OrderIP] => 115.97.1.132
    [OrderId] => 1
    [OrderCode] => ORD-000001
    [CustEmailAdd] => harishmdesai@yahoo.com
    [CustDelAddId] => 1
    [ProdCode] => PK-0002-0004
    [Quantity] => 1
    [PaytMethod] => 2
    [ShippingCharges] => 1
    [TaxedAmount] => 1
    [AppliedCredits] => 10
    [PayableAmount] => 2
    [OrderDate] => 2015-03-19 16:53:46
    [OrderModified] => 0000-00-00 00:00:00
    [OrderStatus] => In Process
    [OrderIPAddress] => 115.97.1.132
)
Array
(
    [SCO_Id] => 1
    [SCO_OrderCode] => ORD-000001
    [SCO_CustEmailAdd] => harishmdesai@yahoo.com
    [SCO_Purchase_Amount] => 1
    [SCO_Credit_Alloted] => 100
    [SCO_OrderDate] => 2015-03-19 16:45:19
    [SCO_OrderIP] => 115.97.1.132
    [OrderId] => 2
    [OrderCode] => ORD-000002
    [CustEmailAdd] => harishmdesai@yahoo.com
    [CustDelAddId] => 2
    [ProdCode] => PK-0002-0004
    [Quantity] => 1
    [PaytMethod] => 2
    [ShippingCharges] => 1
    [TaxedAmount] => 1
    [AppliedCredits] => 0
    [PayableAmount] => 12
    [OrderDate] => 2015-03-20 09:30:02
    [OrderModified] => 0000-00-00 00:00:00
    [OrderStatus] => In Process
    [OrderIPAddress] => 115.97.1.132
)
Array
(
    [SCO_Id] => 2
    [SCO_OrderCode] => ORD-000002
    [SCO_CustEmailAdd] => harishmdesai@yahoo.com
    [SCO_Purchase_Amount] => 1
    [SCO_Credit_Alloted] => 100
    [SCO_OrderDate] => 2015-03-19 17:01:25
    [SCO_OrderIP] => 115.97.1.132
    [OrderId] => 2
    [OrderCode] => ORD-000002
    [CustEmailAdd] => harishmdesai@yahoo.com
    [CustDelAddId] => 2
    [ProdCode] => PK-0002-0004
    [Quantity] => 1
    [PaytMethod] => 2
    [ShippingCharges] => 1
    [TaxedAmount] => 1
    [AppliedCredits] => 0
    [PayableAmount] => 12
    [OrderDate] => 2015-03-20 09:30:02
    [OrderModified] => 0000-00-00 00:00:00
    [OrderStatus] => In Process
    [OrderIPAddress] => 115.97.1.132
)

P.S :所有的值从数据库里

推荐答案

显示rowdata检查前值 SC_Used

Before displaying the rowdata check the value of SC_Used.

如果它是0设置S_OC的值设置为 -

If it is 0 set the value of S_OC to '--'

如果它不是0设置的SC_OC,SC_Amount,SC_Alloted的值 -

If it is not 0 set the value of SC_OC, SC_Amount, SC_Alloted to '--'

然后显示的行

在code:

while ($rows_sco = $validate->FetchAllDatas()) {
    $i = 0;
    if ( 0 == $rows_sco["AppliedCredits"]) {
      $rows_sco["OrderCode"] = '--';
    } else {
      $rows_sco["SCO_OrderCode"] = '--';
      $rows_sco["SCO_Purchase_Amount"] = '--';
      $rows_sco["SCO_Credit_Alloted"] = '--';
    }
    $table .= '<tr>';
    $table .= '<td>'.$rows_sco["SCO_OrderCode"].'</td>';
    $table .= '<td>'.$rows_sco["OrderCode"].'</td>';
    $table .= '<td>'.$rows_sco["SCO_OrderDate"].'</td>';
    $table .= '<td>'.$rows_sco["SCO_Purchase_Amount"].'</td>';
    $table .= '<td>'.$rows_sco["SCO_Credit_Alloted"].'</td>';
    $table .= '<td>'.$rows_sco["AppliedCredits"].'</td>';
    $table .= '<td>'.$rows_sco["SCO_Credit_Alloted"].'</td>';
    $table .= '</tr>';

}

您可能需要更换与0'0'

you may need to replace 0 with '0'

这篇关于逻辑错误显示MySQL表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 21:02