I'm writing a program that queries a database and returns all rows that have a value in any of the 19 columns into a table. The issue I am having is that the values are being sorted by which column has text in it instead of the ID number that I would like to sort by. I'm pretty new to PHP so it may be something that easy or it may require a complete re-write of my code. Any help that you can give me will be greatly appreciated.
<?php
$con= mysqli_connect('localhost','root','spyder11','audits');
echo "<table border = '1'>
<tr>
<th>ID</th>
<th>Auditor</th>
<th>Area</th>
<th>ESP</th>
<th>Date</th>
<th>Safety Finding</th>
</tr>";
for ($x=1; $x<20;$x++){
$y="SOT".$x;
$f=1;
mysqli_query($con,"UPDATE safety SET fixed=0
WHERE fixed!=$f and $y='No'");
}
for ($x=1; $x<20; $x++){
$y="SOT".$x;
mysqli_query($con,"UPDATE safety SET $y = Null WHERE $y ='Yes'");
$result=mysqli_query($con, "SELECT idsafety, auditor, area, esp, date,".$y." FROM safety WHERE SOT".$x." is not null Order BY idsafety");
while ($row = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>". $row["idsafety"]."</td>";
echo "<td>". $row["auditor"]. "</td>";
echo "<td>". $row["area"]. "</td>";
echo "<td>". $row["esp"]. "</td>" ;
echo "<td>". $row["date"]. "</td>";
echo "<td>". $row[$y]."</td>";
echo "</tr>";
}
}
?>