I have the following query written in mysql. It works properly in mysql but when I assign it to the variable in php and try to run it ,it gives an error - "Parse error: syntax error, unexpected identifier "IPRANDPATENTS"". How am I supposed to run this query in php successfully?
<table align="center">
<tr>
<th>RollNo</th>
<th>IPRANDPATENTS</th>
<th>COMPUTERNETWORKS</th>
<th>DATAWAREHOUSINGANDMINING</th>
<th>DESIGNANDANALYSISOFALGORITHMS</th>
<th>SOFTWARETESTINGMETHODOLOGIES</th>
<th>NETWORKPROGRAMMINGLAB</th>
<th>DATAWAREHOUSINGANDMININGLAB</th>
<th>SOFTWARETESTINGLAB</th>
<th>INTERNETOFTHINGS</th>
</tr>
<?php
$sql= "SELECT rollnum,
max((case when subject='IPRANDPATENTS' then gradea end)) as `IPRANDPATENTS`,
max((case when subject='COMPUTERNETWORKS' then gradea end)) as `COMPUTERNETWORKS`,
max((case when subject='DATAWAREHOUSINGANDMINING' then gradea end)) as `DATAWAREHOUSINGANDMINING`,
max((case when subject='DESIGNANDANALYSISOFALGORITHMS' then gradea end)) as `DESIGNANDANALYSISOFALGORITHMS`,
max((case when subject='SOFTWARETESTINGMETHODOLOGIES' then gradea end)) as `SOFTWARETESTINGMETHODOLOGIES`,
max((case when subject='NETWORKPROGRAMMINGLAB' then gradea end)) as `NETWORKPROGRAMMINGLAB`,
max((case when subject='DATAWAREHOUSINGANDMININGLAB' then gradea end)) as `DATAWAREHOUSINGANDMININGLAB`,
max((case when subject='SOFTWARETESTINGLAB' then gradea end)) as `SOFTWARETESTINGLAB`,
max((case when subject='INTERNETOFTHINGS' then gradea end)) as `INTERNETOFTHINGS`
from ocse4year group by rollnum;
";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0)
{
while($row = mysqli_fetch_assoc($result))
{
echo "<tr><td>". $row["rollnum"] .
"</td><td>" . $row["IPRANDPATENTS"] .
"</td><td>" . $row["COMPUTERNETWORKS"] .
"</td><td>" . $row["DATAWAREHOUSINGANDMINING"] .
"</td><td>" . $row["DESIGNANDANALYSISOFALGORITHMS"] .
"</td><td>" . $row["SOFTWARETESTINGMETHODOLOGIES"] .
"</td><td>" . $row["NETWORKPROGRAMMINGLAB"] .
"</td><td>" . $row["DATAWAREHOUSINGANDMININGLAB"] .
"</td><td>" . $row["SOFTWARETESTINGLAB"] .
"</td><td>" . $row["INTERNETOFTHINGS"] .
"</td></tr>";
}
echo "</table>";
}
else{
echo "0 result";
}
$conn-> close();
?>
</table>