Need help in PHP table alignment after getting data from MYSQL

I need help to align all the “tick” in one rows rather than multiple rows after getting data from MYSQL.

As some of the MYSQL data not starting in January (eg. Aug, Sep), how do I get the result to be shown same row as well?

My code is not the cleanest and I do hope there is a neater way of doing it. Appreciate your help. Thanks in advance.

<?php


include 'library/config.php';
include 'library/opendb.php';



$queryname12 = "SELECT * FROM tang WHERE stillhere='yes' ORDER BY fullname ASC";
$result12=mysql_query($queryname12);

if(mysql_num_rows($result12) > 0) {   


while($row12 = mysql_fetch_array($result12))
{
   
        $fullname12      = $row12['fullname'];




$querypaid = "SELECT * FROM expenselist WHERE paid='on' AND fullname = '$fullname12' AND type='Income' AND listyear='2023' AND field='Payment' ORDER BY fullname, listmonth ASC, field";



$resultpaid=mysql_query($querypaid);

echo mysql_error();

echo "<br><table border=1>";
echo "<tr><td width=100 align=middle><font face='Verdana' size='2'><small><b>&nbsp;</td>
<td width=40 align=middle colspan=12><font face='Verdana' size='2'><small><b>Month (Year 2023)</td></tr>";
echo "<td>Name</td><td>Jan</td><td>Feb</td><td>Mar</td><td>Apr</td><td>May</td><td>Jun</td><td>Jul</td><td>Aug</td><td>Sep</td><td>Oct</td><td>Nov</td><td>Dec</td></tr>";

if(mysql_num_rows($resultpaid) > 0) {   
    
    while($rowpaid = mysql_fetch_assoc($resultpaid)){
        $IDpaid            = $rowpaid['ID'];
        $datetodaypaid     = $rowpaid['datetoday'];    
        $fullnamepaid      = $rowpaid['fullname'];
        $remarkspaid       = $rowpaid['remarks'];
        $monthpaid         = $rowpaid['listmonth'];
        $yearpaid          = $rowpaid['listyear'];




    $remarkspaid1 = explode(" ", $rowpaid['remarks']);


$ar0 = $remarkspaid1[0]; //monthly
$ar1 = $remarkspaid1[1]; //payment
$ar2 = $remarkspaid1[2]; //for
$ar3 = $remarkspaid1[3]; //Sep-2023
$ar4 = $remarkspaid1[4]; //etc,etc


if ($ar0 == "Monthly" AND $ar1 == "payment" AND $ar2 == "for" ) 
{
$monthis1 = $remarkspaid1[3];  
$cutoutmonth = substr($monthis1, 0, 3); 
    
    
    if ($cutoutmonth == "Jan"){
        $mthpaid = "1";
    }
            
    else if ($cutoutmonth == "Feb"){
        $mthpaid = "2";
    }
    
    else if ($cutoutmonth == "Mar"){
        $mthpaid = "3";
    }
    else if ($cutoutmonth == "Apr"){
        $mthpaid = "4";
    }
    else if ($cutoutmonth == "May"){
        $mthpaid = "5";
    }
    else if ($cutoutmonth == "Jun"){
        $mthpaid = "6";
    }
    else if ($cutoutmonth == "Jul"){
        $mthpaid = "7";
    }
    else if ($cutoutmonth == "Aug"){
        $mthpaid = "8";
    }
    else if ($cutoutmonth == "Sep"){
        $mthpaid = "9";
    }
    else if ($cutoutmonth == "Oct"){
        $mthpaid = "10";
    }
    else if ($cutoutmonth == "Nov"){
        $mthpaid = "11";
    }
    else if ($cutoutmonth == "Dec"){
        $mthpaid = "12";
    }
    
}

$shortname = substr($fullname12, 0, 5) . "..";


echo "<tr><td width=20 valign=top align=middle bgcolor=$bgcolor><font face='Verdana' size='2'><small>";
echo $shortname ."</td>";

echo "<td>";
if ($mthpaid == 1){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 2){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 3){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 4){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 5){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 6){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 7){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 8){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 9){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 10){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 11){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td>";

echo "<td>";
if ($mthpaid == 12){
    
echo "<input id="online" name="monthpaid" type="checkbox" title="". $cutoutmonth. "Month paid (name: monthpaid)" checked>"; 
}
    else {
        echo "0";
    }
echo "</td></tr>";

}
}
echo "</table>";
}
}

?>