joseph joseph - 7 months ago 9
SQL Question

How to use OR in 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 this code in my program and works but I have problem in
if($row["id"]==201102887 || null)
because do not accept null while in my database there is null.

I want if id is equal to 201102887 or null (no value) then run the statements.

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.