如何在PHP语言中使用OR


How to use OR in the PHP language

<?php
$con = mysqli_connect('localhost', 'root', '');
if(!$con)
{
    die("not ok");
}
mysqli_select_db($con,"uoh");  
$q = "SELECT * FROM courses 
LEFT JOIN degree_plan ON degree_plan.course_number= courses.course_number 
LEFT JOIN student_record ON courses.course_number= student_record.course_number 
LEFT JOIN equal ON equal.sn= student_record.sn
AND student_record.id= 201102887
WHERE degree_plan.major='COE';";
$result = mysqli_query($con , $q ) ;
if($result){
   echo "<br />";
   echo "<table>";
   echo "<tr>";
   echo "<th>id</th>";
   echo "</tr>";
while($row = mysqli_fetch_array($result))
{
   if($row["id"]==201102887 || null)
   {
   echo "<tr>";
   echo "<td>" . $row["id"]. "</td>";
   echo "</tr>";
   }
    else
  {} 
}
echo "</table>";
   }
?>

我的程序中有一些代码并且可以工作,但是我对if($row["id"]==201102887 || null)有问题,因为它不接受null,尽管null存在于我的数据库中。

我想让它如果id等于 201102887null(无值(,则语句执行。

您必须在 OR ||的两侧使用变量代码应if($row["id"]==201102887 || $row["id"]== null)这应该有效。

这样用

if($row["id"]==201102887 || $row["id"]== null){
}

如果你想使用Logical operators你应该在if条件中写两个语句

语句 1 : $row["id"] == 201102887

语句 2 : $row["id"] == 空

在 if 条件下,两个语句之间的 putt ||

 if($row["id"]==201102887 || $row["id"]== null){
      // do something
    }

使用if的另一种方法

     if($row["id"]==201102887 || $row["id"]== null):
      // do something
     endif;