dpxyfa4718 2015-01-31 13:59
浏览 38

显示0.1-1.9,2.0-2.9等之间的数字,

As the title says I'm trying to display numbers between 0.1-1.9 as Season 1 then 2.0-2.9 season 2 etc., that's what I have tried so far

 $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>';

And here is the result: http://i.imgur.com/VeN8pD8.png pretty close

  • 写回答

1条回答 默认 最新

  • dongyang4615 2015-01-31 14:04
    关注

    You can derive the season easily in SQL. In MySQL, for instance, you can use substring_index():

    SELECT Patch_No, Created, SUBSTRING_INDEX(Patch_No, '.', 1) as Season
    FROM info
    ORDER BY Patch_NO DESC;
    

    Other databases have similar functionality that can be used for this purpose.

    Note that this is just extracting the first digit from Patch_No, which appears to be your intention.

    This actually separates 0.1-0.9 from 1.0, which makes sense to me. If you want those as a single season, you can use a case statement.

    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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题