Displaying Data From Custom Table By Year

I have a custom wordpress table and am trying to get all rows in the db separated by year. My code now:

echo “<table width=’100%’>”;
for ($year = date(“Y”); $year >= 2017; –$year) {
echo (“<tr><th>$year</th></tr>”);
echo (“<tr><th>Champions</th>”);

echo (“<th>Score</th>”);

echo (“<th>Date</th></tr>”);

global $wpdb;
$clubmatch = $wpdb->get_results(“SELECT * FROM wp_club ORDER BY gamedate DESC”);

foreach($clubmatch as $row){

echo “<tr><td>” . $row->names . “</td>”;
echo “<td>” . $row->score . “</td>”;
echo “<td>” . $row->gamedate . “</td></tr>”;
}
echo (“<tr><td style=’padding: 20px;’></td></tr>”);

}
echo ‘</table>’;

This gives me the following on screen:

2018
Champions Score Date
Sam Jones – Peggy Jones 81.43 2018-03-01
Joseph Parks – Carmen Parks 70.85 2017-12-17

2017
Champions Score Date
Sam Jones – Peggy Jones 81.43 2018-03-01
Joseph Parks – Carmen Parks 70.85 2017-12-17

How do I get it to display like this? Each row under the proper year?

2018
Champions Score Date
Sam Jones – Peggy Jones 81.43 2018-03-01

2017
Champions Score Date
Joseph Parks – Carmen Parks 70.85 2017-12-17

Thanks in advance!

Read more here:: Displaying Data From Custom Table By Year

Leave a Reply

Your email address will not be published. Required fields are marked *