joseph joseph - 7 months ago 13
PHP Question

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>";
}

?>


I have some code in my program and it works, but I have problem with
if($row["id"]==201102887 || null)
because it does not accept
null
, despite
null
being present in my database.

I want to make it so that if
id
is equal to
201102887
or
null
(no value) then the statements execute.

Answer

You will have to use variables on both sides of the OR || The code should be if($row["id"]==201102887 || $row["id"]== null) This should work.