【发布时间】:2018-08-15 23:55:17
【问题描述】:
我有一个自定义 wordpress 表,并试图让数据库中的所有行按年份分隔。我现在的代码:
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>';
这会在屏幕上显示以下内容:
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
我如何让它像这样显示?正确年份下的每一行?
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
提前致谢!
【问题讨论】:
标签: php mysql wordpress foreach