The following code displays table on the form but I need to format the table in a specific fashion.
The desired output is displayed in image. So I need to manipulate the query someway where I can convert Sprinkler_ID columns to 1,2,3,4,5,6,7,8. So, if there is no Sprinkler_ID let say "2" in our original table then the desired table should print "no" in the "2" field otherwise YES.

<?php
include('config.php');
echo "<h4>Current Schedules</h4>";
echo "<table border=2 >";
echo "<tr>";
echo "<td><b>Sprinkler_Id</b></td>";
echo "<td><b>Schedule_Id</b></td>";
echo "<td><b>Starttime</b></td>";
echo "<td><b>Stoptime</b></td>";
echo "<td><b>Monday</b></td>";
echo "<td><b>Tuesday</b></td>";
echo "<td><b>Wednesday</b></td>";
echo "<td><b>Thursday</b></td>";
echo "<td><b>Friday</b></td>";
echo "<td><b>Saturday</b></td>";
echo "<td><b>Sunday</b></td>";
echo "</tr>";
$sql = "SELECT daystime.*, Sprinkler_ID FROM daystime, scheduler WHERE daystime.id = scheduler.DaysTime_ID ORDER BY Sprinkler_ID, daystime.id";
$results=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($results))
{
$id = $row['id'];
echo "<tr>";
echo "<td valign='top'>" . nl2br( $row['Sprinkler_ID']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['id']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['starttime']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['stoptime']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['mon']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['tue']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['wed']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['thu']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['fri']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['sat']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['sun']) . "</td>";
echo "</tr>";
}
echo "</table>";
?>

Sprinkler_ID?nullor empty?