You could clean it up a little by replacing lines 11-51 with:
<?php
$Downloads = new WA_MySQLi_RS("Downloads",$DBConnection,0);
$Downloads->setQuery("SELECT * FROM download WHERE DownloadType = ? AND Live = 1 ORDER BY DownloadDate ASC");
$PageContents->bindParam("i", "".($PageContents->getColumnVal("ServicesID")) ."", "-1"); //paramOffersID
$Downloads->execute();
?>
Your code that starts on line 99:
<?php if ($Downloads->TotalRows > 0) { // Show if mysqli recordset not empty ?>
<div class="container downloadWrapper">
<h3 class="heading-1">2018</h3>
<div class="container downloadContainer">
<?php
$wa_startindex = 0;
while(!$Downloads->atEnd()) {
$wa_startindex = $Downloads->Index;
?>
<a class="link-text downloadLnk" href="downloads/<?php echo($Downloads->getColumnVal("DownloadFile")); ?>" target="_blank"><?php echo($Downloads->getColumnVal("DownloadTitle")); ?><br>
</a>
<?php
$Downloads->moveNext();
}
$Downloads->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
</div>
</div>
<?php } // Show if mysqli recordset not empty ?>
You could update to something like:
<?php if ($Downloads->TotalRows > 0) { // Show if mysqli recordset not empty ?>
<div class="container downloadWrapper">
<?php
$showYear = "";
?>
<?php
$wa_startindex = 0;
while(!$Downloads->atEnd()) {
$wa_startindex = $Downloads->Index;
?>
<?php
if ($showYear != date("Y", strtotime($Downloads->getColumnVal("DownloadDate")))) {
?>
<h3 class="heading-1"><?php echo(date("Y", strtotime($Downloads->getColumnVal("DownloadDate"))); ?></h3>
<div class="container downloadContainer">
<?php
}
?>
<a class="link-text downloadLnk" href="downloads/<?php echo($Downloads->getColumnVal("DownloadFile")); ?>" target="_blank"><?php echo($Downloads->getColumnVal("DownloadTitle")); ?><br>
</a>
<?php
if ($showYear != date("Y", strtotime($Downloads->getColumnVal("DownloadDate")))) {
$showYear = date("Y", strtotime($Downloads->getColumnVal("DownloadDate"));
?>
</div>
<?php
}
?>
<?php
$Downloads->moveNext();
}
$Downloads->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
</div>
<?php } // Show if mysqli recordset not empty ?>