gpt4 book ai didi

php - 从数据库中选择下一个事件

转载 作者:行者123 更新时间:2023-11-30 22:35:40 25 4
gpt4 key购买 nike

我正在开发一个选择日期列表并突出显示下一个事件的函数。我已经设法突出显示所有 future 事件,但我只想突出显示最近的 future 事件。如何才能做到这一点?

<?php
function racesbydate($sql) {
include 'connect.php';
$year = $_GET['year'];
$get = $year.'%';
$select = $conn->prepare($sql);
$select->bind_param('s', $get);
$select->execute();
$select->store_result();
if ($select->num_rows > 0) {
echo "<div class='races' id='$year' style='display:block'>
<table>\n<th colspan='5'>Cycling Season $year </th>\n
<tr id='information'>\n
<th id='date'>Date</th>\n
<th id='race'>Race</th>\n
<th id='route'>Route</th>\n
<th id='info'>Entry</th>\n
<th id='rizultz'>Results</th>";
$meta = $select->result_metadata();
while ($field = $meta->fetch_field()) {
$params[] = &$row[$field->name];
}
call_user_func_array(array($select, 'bind_result'), $params);
while ($select->fetch()) {
$today = date("Y-m-d");
$date = new DateTime($row['date']);
$formatted_date = $date->format('d/m/Y');
if ($row['date'] > $today) {
if ($row['infoID'] != "0") {
echo "<tr class='racedetails' id='nextrace' >\n
<td class='dark' id='date'>".$formatted_date."</td>\n
<td class='light' id='race'>".$row["title"]."</td>\n
<td class='dark' id='route'>".$row["route"]."</td>\n
<td class='light' id='info'><a href='".$row["infoID"]."'>Info</a></td>\n
<td class='dark' id='rizults'>N/A</td>\n</tr>\n";
}
} else {
if (($row['infoID'] != "0") && ($row['resultID'] !="0" )) {
echo "<tr class='racedetails' id='race' >\n
<td class='dark' id='date'>".$formatted_date."</td>\n
<td class='light' id='race'>".$row["title"]."</td>\n
<td class='dark' id='route'>".$row["route"]."</td>\n
<td class='light' id='info'><a href='".$row["infoID"]."'>Info</a></td>\n
<td class='dark' id='rizults'><a href='".$row["resultID"]."'>Results</a></td>\n</tr>\n";
}
}

}
}
echo "</table>\n</div>";
$select->close();
}

当前结果

<tr class='racedetails' id='nextrace' ><td class='dark' id='date'>06/01/2016</td></tr>
<tr class='racedetails' id='nextrace' ><td class='dark' id='date'>08/02/2016</td></tr>

目标结果

<tr class='racedetails' id='nextrace' ><td class='dark' id='date'>06/01/2016</td></tr>
<tr class='racedetails' id='race' ><td class='dark' id='date'>08/02/2016</td></tr>

最佳答案

如果我没理解错的话,你只需要一个标志来存储是否已经看到下一场比赛的信息:

    :
call_user_func_array(array($select, 'bind_result'), $params);
$nextRace = true;
while ($select->fetch()) {
$today = date("Y-m-d");
$date = new DateTime($row['date']);
$formatted_date = $date->format('d/m/Y');
if ($row['date'] > $today) {
if ($row['infoID'] != "0") {
$cssId = $nextRace ? 'nextrace' : 'race';
$nextRace = false;
echo "<tr class='racedetails' id='".$cssId."' >\n
<td class='dark' id='date'>".$formatted_date."</td>\n
<td class='light' id='race'>".$row["title"]."</td>\n
<td class='dark' id='route'>".$row["route"]."</td>\n
<td class='light' id='info'><a href='".$row["infoID"]."'>Info</a></td>\n
<td class='dark' id='rizults'>N/A</td>\n</tr>\n";
}
} else {
:

这假设比赛的顺序按日期升序(您的示例表明)。

关于php - 从数据库中选择下一个事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32613729/

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