1

你能帮我解决这个问题吗?我的 else 语句中的更新查询没有执行,但它在 if 语句中工作。这是代码。

        while($qtytoAdd > 0) {
    $remBalance = mysql_result(mysql_query('SELECT `est_qty` - `qty_rec` as balance FROM `estimates` WHERE `proj_id` = "'.$proj_id.'" AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `qty_rec` <> `est_qty` ORDER BY `item_id` ASC'), 0);
    $balid = mysql_result(mysql_query('SELECT `est_id` FROM `estimates` WHERE `proj_id` = "'.$proj_id.'" AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `qty_rec` <> `est_qty` ORDER BY `item_id` ASC'), 0);
    $currRec = mysql_result(mysql_query('SELECT `qty_rec` FROM `estimates` WHERE `proj_id` = "'.$proj_id.'" AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `qty_rec` <> `est_qty`'), 0);
    $currid = mysql_result(mysql_query('SELECT `req_id` FROM `requestdetails` JOIN `request` USING(`req_id`) WHERE `proj_id` = "'.$proj_id.'" AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `req_qty` <> `current_rec_qty` ORDER BY `req_id` ASC'), 0);

        if(($remBalance - $qtytoAdd) >= 0) {
            mysql_query('UPDATE `estimates` SET `qty_rec` = `qty_rec` + "'.$qtytoAdd.'" WHERE `proj_id` = "'.$proj_id.'" AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `est_id` = "'.$balid.'"');
                $qtytoAdd = 0;
        mysql_query('UPDATE `estimates` SET `qty_onhand` = `qty_rec` - `qty_rel` WHERE `proj_id` = '.$proj_id.' AND `qty_rec` <> `est_qty` AND `mat_id` = '.mat_id_from_mat_desc($materials).' AND `est_id` = '.$balid.'');
            } else {
                mysql_query('UPDATE `estimates` SET `qty_rec` = "'.$remBalance.'" + "'.$currRec.'" WHERE `proj_id` = "'.$proj_id.'" AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `est_id` = "'.$balid.'"');
                $qtytoAdd = $qtytoAdd - $remBalance;
        mysql_query('UPDATE `estimates` SET `qty_onhand` = `qty_rec` - `qty_rel` WHERE `proj_id` = '.$proj_id.' AND `qty_rec` <> `est_qty` AND `mat_id` = '.mat_id_from_mat_desc($materials).' AND `est_id` = '.$balid.'');
            }
        }

我真的不知道问题是什么。我正在谈论的查询是这个:

mysql_query('UPDATE `estimates` SET `qty_onhand` = `qty_rec` - `qty_rel` WHERE `proj_id` = '.$proj_id.' AND `qty_rec` <> `est_qty` AND `mat_id` = '.mat_id_from_mat_desc($materials).' AND `est_id` = '.$balid.'');
4

3 回答 3

0

如果它在 else 语句中不起作用,为什么不尝试回显查询,然后复制该查询并将其粘贴到查询分析器或 phpmyadmin 中并检查它是否运行。像这样的东西:

  else {
      $query="enter your query here";
      echo $query;
      mysql_query($query);
  }

在浏览器中打印查询后,您将知道正在运行什么查询并检查它是否正确。需要一些调试技巧

于 2013-02-01T14:59:27.537 回答
0

尝试这个

      else {
            mysql_query('UPDATE `estimates` SET `qty_rec` = "'.$remBalance + $currRec.'" WHERE `proj_id` = "'.$proj_id.'" AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `est_id` = "'.$balid.'"');

    mysql_query('UPDATE `estimates` SET `qty_onhand` = `qty_rec` - `qty_rel` WHERE `proj_id` = '.$proj_id.' AND `qty_rec` <> `est_qty` AND `mat_id` = '.mat_id_from_mat_desc($materials).' AND `est_id` = '.$balid.'');
        }
        $qtytoAdd = $qtytoAdd - $remBalance;
    }

编辑。

尝试用这个替换你的查询

 mysql_query('UPDATE `estimates` SET `qty_onhand` = `qty_rec` - `qty_rel` WHERE `proj_id` = "'.$proj_id.'" AND `qty_rec` <> `est_qty` AND `mat_id` = "'.mat_id_from_mat_desc($materials).'" AND `est_id` = "'.$balid.'"');
于 2013-02-01T15:07:47.330 回答
-1

我遇到了同样的问题。在你的 else 循环中使用函数会起作用

else
{
    $update_function=update_function($ud_id,$subject,$to_user,$from_user);
    [//pass your variables instead of $ud_id,$subject,$to_user,$from_user]
}

function update_function($ud_id,$subject,$to_user,$from_user)
{               
    //place your query over here    
    $query=mysql_query("UPDATE `email_configuration` SET `subject`='$subject',`to_user`='$to_user',`from_user`='$from_user' WHERE id='$ud_id'");    
    echo "Record Updated";                              
}
于 2015-11-05T21:43:07.300 回答