1

我有ps_orders(total_paid) 和 (current_state)的表

如果当前状态为“3”,则写入$total_paid 如果不是“3”,则写入“0”

我提取了$total_paid值,但我无法声明$current_state变量

$query_cod = "SELECT total_paid FROM ps_orders WHERE current_state = 3":

$result_cod = mysql_query($query_cod);

    while ($row_cod = mysql_fetch_array($result_cod))
    $total_paid = $row_cod['total_paid'];

    if ($current_state == 3) {
    fwrite($file, "total_paid"); //38
    } 

    elseif ($current_state == 2) {
    fwrite($file, "|"); //38
    } 
4

3 回答 3

0

尝试这个 :

$query_cod = "SELECT total_paid, current_state FROM ps_orders";
$result_cod = mysql_query($query_cod);

while ($row_cod = mysql_fetch_array($result_cod)) {
    $total_paid = $row_cod['total_paid'];
    $current_state = $row_cod['current_state'];
    if ($current_state == 3) {
        fwrite($file, "total_paid"); //38
    } 

    elseif ($current_state == 2) {
        fwrite($file, "|"); //38
    } 
}

编辑:正如@Ivan Hanák 所说,只要where您的 SQL 查询中有该语句,您的比较就没有用。我已经更正了我的代码,我想这就是你想要做的......

而且,不要使用mysql_query,它已被弃用。看看PDO

于 2013-11-07T09:33:39.377 回答
0

已解决,这里有代码,但我有一个小问题

$query_cod = "SELECT total_paid, current_state FROM ps_orders WHERE id_order = " 。$id_order; $result_cod = mysql_query($query_cod);

    while ($row_cod = mysql_fetch_array($result_cod)) 

        {
            $total_paid = $row_cod['total_paid'];
            $current_state = $row_cod['current_state'];

            if ($current_state == 3)
            {
                fwrite($file, "$total_paid" . "|"); //40
                fwrite($file, "EUR|"); //41
                fwrite($file, "CON|"); //42 
            } 

            elseif ($current_state == 2)
            {
                fwrite($file, "|"); //40
                fwrite($file, "|"); //41
                fwrite($file, "|"); //42
            } 

如果我插入 'total_paid' 显示“总支付” 如果我插入 $total_paid 显示正确的价格 但它应该与“总支付”一起使用......?正确的?

于 2013-11-08T14:56:21.170 回答
0

您的循环中有错误。

看,您正在根据条件从数据库中获取行WHERE current_state = 3"。因此,以下if/else语句是无用的,因为该变量$row_cod仅包含有关的记录,current_state = 3并且在单行中没有这样的 key current_state,因为您不在 sql 查询中请求。

您应该删除该WHERE子句,然后进行比较。

(或者只是提供更多信息,你想完成什么。)

编辑:

if ($row_cod['current_state'] == 3)
    fwrite($file, "total_paid");
elseif ($row_cod['current_state'] == 2)
    fwrite($file, "|");

不要忘记添加current_state到您的 sql 查询中

于 2013-11-07T12:13:05.577 回答