= 2017; --$ye-6ren">
gpt4 book ai didi

php - Wordpress - 获取 HTML 表格中的所有行

转载 作者:行者123 更新时间:2023-11-29 02:42:13 25 4
gpt4 key购买 nike

我有一个自定义的 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

提前致谢!

最佳答案

更改 SQL 查询,使其按字段 gamedate 的年份过滤结果。所以使用这个:(为了清楚起见,代码缩进了)

$clubmatch = $wpdb->get_results(
"SELECT * FROM wp_club " .
"WHERE YEAR(gamedate) = '$year' " .
"ORDER BY gamedate DESC"
);

..代替:

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

关于php - Wordpress - 获取 HTML 表格中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49159394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com