正如标题所说,我试图在第一季度以及第二季度2.0-2.9之间显示0.1-1.9之间的数字,这就是我到目前为止所尝试的数据
$sql="SELECT Patch_No, Created FROM info ORDER BY Patch_NO DESC";
$result = $conn->query($sql);
while($data = $result->fetch_assoc()){
if(!isset($seasons[ceil($data['Patch_No'])])||is_int($data['Patch_No'])&&ceil($data['Patch_No'])==$data['Patch_No']+1){
$seasons[ceil($data['Patch_No'])]=ceil($data['Patch_No']);
echo '<hr><i>SEASON '.ceil($data['Patch_No']).'<br></i><hr>';
}
echo '<a href="delete_patch.php?Patch_No='.$data['Patch_No'].'" alt="'.$data['Created'].'" title="'.$data['Created'].'">
'.$data['Patch_No'].'</a><br>';
}
echo '<hr><hr><a href="index.php">CMS</a>';
结果如下:http://i.imgur.com/VeN8pD8.png非常接近
答案 0 :(得分:0)
您可以在SQL中轻松推导出季节。例如,在MySQL中,您可以使用substring_index()
:
SELECT Patch_No, Created, SUBSTRING_INDEX(Patch_No, '.', 1) as Season
FROM info
ORDER BY Patch_NO DESC;
其他数据库具有可用于此目的的类似功能。
请注意,这只是从Patch_No
中提取第一个数字,这似乎是您的意图。
这实际上将0.1-0.9与1.0分开,这对我来说很有意义。如果您想将这些作为一个季节,您可以使用case
声明。
SELECT Patch_No, Created,
(CASE WHEN Patch_No like '%0' THEN '1'
ELSE SUBSTRING_INDEX(Patch_No, '.', 1)
END) as Season
FROM info
ORDER BY Patch_NO DESC;