我有一個PHP IF語句,基於IF條件將不同的SQL結果保存在一個PHP變量($ sql)中,但它會基於一個條件(第一個條件)持續返回SQL結果,而不管用戶輸入POST'd值。這個PHP IF語句有什麼問題?
所有SQL語句在單獨進入phpMyAdmin時都會按預期工作(同時將$ row3和$ row4更改爲存在的實際值),而不是PHP IF語句。
任何人都可以看到我在做什麼錯在這裏,如果可能的話,建議我需要做什麼不同?我知道我沒有PHP/MySQL的專家,但我難倒:(
任何幫助或建議是極大的讚賞。在此先感謝。
$row3 = $_POST['groups'];
$row4 = $_POST['othercode-all'];
IF ($row3='-all-' && ($row4='-all-'))
{
$sql ="SELECT
email,
accountgroup, othercode
FROM
(SELECT
email AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email2 AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email3 AS email,
accountgroup, othercode
FROM
accounts) account
WHERE
email LIKE '%@%'";
}
ELSEif ($row3!='-all-' && ($row4='-all-'))
{
$sql ="SELECT
email,
accountgroup, othercode
FROM
(SELECT
email AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email2 AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email3 AS email,
accountgroup, othercode
FROM
accounts) account
WHERE
email LIKE '%@%'
AND accountgroup = '$row3'";
}
ELSEIF ($row4 != '-all-' && ($row3 = '-all-'))
{
$sql ="SELECT
email,
accountgroup, othercode
FROM
(SELECT
email AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email2 AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email3 AS email,
accountgroup, othercode
FROM
accounts) account
WHERE
email LIKE '%@%'
AND othercode = '$row4'";
}
ELSE
{
$sql ="SELECT
email,
accountgroup, othercode
FROM
(SELECT
email AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email2 AS email,
accountgroup, othercode
FROM
accounts
UNION ALL
SELECT
email3 AS email,
accountgroup, othercode
FROM
accounts) account
WHERE
email LIKE '%@%'
AND accountgroup = '$row3' AND othercode = '$row4'";
}
同樣的故事發生在ELSEIF上。 – briosheje
你是個天才!好吧,和我相比,你是大聲笑。非常感謝! 目前我只是很高興現在能夠正常工作,但我會嘗試並按照最後一段的順序進行操作:) – user2968514