我正在使用表p和g來處理兩個表的mysql數據庫。 這裏我試圖檢查從表'p'上的選擇查詢返回的變量$ ureciever的值是否爲空,並基於該更新表'g'上的兩個不同列'partner1'和'partner2'與會話用戶名變量。在代碼的一次迭代中,只應更新'partner1'和'partner2'中的一個。
if(empty($ureciever)) {
{
$query ="UPDATE g
SET partner1= '".$_SESSION['username']."'
WHERE packageg = '$upackage' AND banned = 0 AND partner1 =''
ORDER BY useridg ASC
LIMIT 1";
$result = mysql_query($query);
$count = mysql_affected_rows($conn);
}
if($count == 1){
$countdown = time() + 648000;
$query = "UPDATE p AS p
JOIN g AS g ON p.username = g.partner1
SET p.reciever = g.usernameg, p.time_expires = '$countdown'
WHERE p.username ='".$_SESSION["username"]."'";
$result = mysql_query($query);
$count1 = mysql_affected_rows($conn);
}
上面的代碼段來執行正確,但是,如果被測試的條件爲假根本無法運行應運行交替代碼。我檢查了我的括號,分號,記錄了測試條件,沒有任何積極影響。這是下面給我的問題。
else if($count != 1){
$query= "UPDATE g
SET partner2 = '".$_SESSION['username']."'
WHERE packageg = '$package' AND banned = 0 AND partner2 =''
ORDER BY useridg ASC
LIMIT 1";
$result2 = mysql_query($query);
$count2 = mysql_affected_rows($conn);
}
if ($count2 == 1)
{
$countdown = time() + 648000;
$query = "UPDATE p AS p
JOIN g AS g ON p.username = g.partner2
SET p.reciever = g.usernameg, p.time_expires = '$countdown'
WHERE p.username ='".$_SESSION["username"]."'";
$result = mysql_query($query);
$count1 = mysql_affected_rows($conn);
}
}
else{
$_SESSION['paired'] = "You have been matched to pay someone. Please be quick";
}
空返回true或false ...您的條件0或1 ==「」永不返回true使用empty($ var)|| $ var ==「」 –
首先,這個語句if(empty($ ureciever)=='')是錯誤的,不必檢查''空本身檢查它是否正確if(empty($ ureciever)) –