IF 조건을 기반으로 PHP 변수 ($ sql)에 다른 SQL 결과를 저장하는 PHP IF 문이 있지만 SQL 문에 대한 결과와 관계없이 하나의 조건 (첫 번째 조건)을 기반으로 SQL 결과를 반환합니다. 사용자가 POST'd 값을 입력합니다.이 PHP IF 문은 무엇이 잘못 되었습니까?
PHP 문을 사용하지 않고 모든 SQL 문이 phpMyAdmin에 개별적으로 입력 될 때 (예상되는 $ row3 및 $ row4를 실제 값으로 변경하는 경우) 예상대로 작동합니다.
내가 여기서 잘못하고있는 것을 누군가 볼 수 있습니까? 가능하다면 다르게 할 필요가있는 조언을 할 수 있습니까? 나는 어떤 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