简体   繁体   English

如果在PHP中其他条件如何如何使用mysql像运算符一样

[英]how to use mysql like operator inside if else condition in php

I written mysql like operator inside if else condition in php. 我写了像运算符里面的mysql,如果其他条件在php。 But am not getting output, Can anyone tell me how to use it. 但是我没有得到输出,谁能告诉我如何使用它。 I am giving my code below 我在下面给出我的代码

   if ($role == "admin")
{
    $sql="SELECT * FROM registration";
}
elseif($role == 'M%')
{
    $sql="SELECT * FROM registration where reporting_manager='$role' OR role='$role'";
}
else
{
    $sql="SELECT * FROM registration WHERE role='$role'";
}

but its not taking the second condition, directly going to last. 但它没有采取第二个条件,直接持续到最后。 What the mistake i had done in this code, or how to write the like operator in if else condition. 我在此代码中犯了什么错误,或者在其他情况下如何编写like运算符。 Thanks in advance 提前致谢

You are mixing mysql with php. 您正在将mysql与php混合使用。 use the following PHP: 使用以下PHP:

elseif(strtoupper($role[0]) === 'M')

Try this one query;) 试试这个查询;)

$sql = "SELECT *
      FROM registration
      WHERE ('$role' = 'admin')
      OR ('$role' = 'M%' AND (reporting_manager='$role' OR role='$role')) 
      OR (role='$role')";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM