更新IF语句中的多个变量

时间:2017-09-16 09:00:37

标签: php if-statement

我在更新IF语句中的多个变量时遇到了一些麻烦,并且不确定我哪里出错了。

这是我的代码:

$id = $_POST['retrive_quantity'];  
$n_quantity = $_POST['n_quantity'];


$result2 = mysql_query ("SELECT * FROM stock_control WHERE id = '$id' ");

while ($row1 = mysql_fetch_array($result2))
{
  $quantity=$row1['quantity'];
  $threshold=$row1['threshold'];
  $emailSent=$row1['email_sent'];
  $orders_status=$row1['orders_status'];
  $orders=$row1['orders'];
}

if ($quantity + $n_quantity > $threshold && $emailSent == 2) {
    $update=0 && $orders_status=0 && $orders=0;
 } else {
    $update=2 && $orders_status=1 && $orders=$orders;
}

mysql_query("UPDATE stock_control SET quantity=quantity + '$n_quantity', 
email_sent = '$update', orders_status = '$orders_status', orders = '$orders' 
WHERE id = '$id' ");

IF语句的第一行起作用,也只使用其中一个变量,但失败了多个。

2 个答案:

答案 0 :(得分:3)

您无法更新此类变量,必须与@Effect() someEffect$: Observable<Action> = this.actions$ .ofType<Your_Type>(Your_Action) .withLatestFrom(this.store$.select(state => state.users.isUserLoggedIn)) .filter(([action, isUserLoggedIn]) => isUserLoggedIn) // here, you'll receive the actions only is the user is logged in // ... your code for the effect

分开
;

答案 1 :(得分:1)

在if块

中使用之前声明变量
$id = $_POST['retrive_quantity'];  
$n_quantity = $_POST['n_quantity'];
$update=2;
$orders_status=1;
$orders=0;
$result2 = mysql_query ("SELECT * FROM stock_control WHERE id = '$id' ");

while ($row1 = mysql_fetch_array($result2))
{
  $quantity=$row1['quantity'];
  $threshold=$row1['threshold'];
  $emailSent=$row1['email_sent'];
  $orders_status=$row1['orders_status'];
  $orders=$row1['orders'];
}

if ($quantity + $n_quantity > $threshold && $emailSent == 2) {
    $update=0;
    $orders_status=0;
    $orders=0;
 } else {
    $update=2; 
    $orders_status=1;
    $orders=$orders;
}

mysql_query("UPDATE stock_control SET quantity=quantity + '$n_quantity', 
email_sent = '$update', orders_status = '$orders_status', orders = '$orders' 
WHERE id = '$id' ");