mysql - 如果“a”==“b”echo“discount”

时间:2015-12-01 13:12:24

标签: php mysql sql database

我正在寻找解决问题的方法。

如果我搜索的电子邮件都在我的数据库中,它应该回显“折扣”,否则它应该回应“没有折扣”

 //Database is connected
 $amail= "SELECT `mail` FROM `wunderte_wp793`.`Newsmail` WHERE `mail` =  (\'" . $_GET['mail'] . "\');";
        $resultamail =  $mysqli->query($amail); // query

 $email= "SELECT `email` FROM `wunderte_wp793`.`message` WHERE `email` =  (\'" . $_GET['mail'] . "\');";
        $resultemail =  $mysqli->query($email); // query

 while($resultamail == $resultemail){
        echo "Discount";
           }

        else {
        echo "NULL discount";
            }

1 个答案:

答案 0 :(得分:1)

使用MySQL if

SELECT if(mail=email,'Discount','NULL discount') result FROM 
`wunderte_wp793` 
WHERE `mail` =  'xyz' or email='xyz'

MySQL IF函数是MySQL控制流函数之一,它根据条件返回值。