dqpfkzu360216 2018-09-04 09:55
浏览 8
已采纳

php从表中选择有限数量的数据,并按日期顺序进行延迟加载

I am using lazy loading to load data from database to device the limit is 20 but my problem lies when I pull the data from table because I have to order it by latest next date.

eg. I pull all data for today then tommorrow and then so on I cant use the id to keep track of what I loaded becuase the entries have different dates when entered

this is and example of my table. please note that my table can have thousands of entries

|  id   | name  |    date    |   time   |
|   0   | name1 | 2018-09-30 | 01:00:00 |
|   1   | name2 | 2019-01-10 | 15:30:00 |
|   2   | name3 | 2019-09-30 | 10:20:00 |
|   3   | name4 | 2018-05-20 | 14:10:00 |
|   4   | name5 | 2020-09-02 | 01:30:00 |
|   5   | name6 | 2018-10-30 | 14:00:00 |

this is what my sql php script looks like. I know its not right but its an example of what im triying to do

SELECT * FROM table WHERE date >= '$today' AND id >= '$lastId' ORDER BY date ASC LIMIT 20

as you can see the id increments but the dates dont increment because it can be entered with any future date. I apologize for my bad english. Please can anyone help me

  • 写回答

1条回答 默认 最新

  • dongwen6743 2018-09-04 10:06
    关注

    to paginate : you can use php or ajax and the last's is recommended:

    <?php
    
    $limit = 2;  
    if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };  
    $start_from = ($page-1) * $limit;  
    
    $sql = "SELECT * FROM table ORDER BY field ASC LIMIT $start_from, $limit";  
    $rs_result = mysql_query ($sql);  
    ?>
    <table class="table table-bordered table-striped">  
    <thead>  
    <tr>  
    <th>title</th>  
    <th>body</th>  
    </tr>  
    </thead>  
    <tbody>  
    <?php  
    while ($row = mysql_fetch_assoc($rs_result)) {  
    ?>  
                <tr>  
                <td><? echo $row["field"]; ?></td>  
    
                </tr>  
    <?php  
    };  
    ?>  
    </tbody>  
    </table>    
    

    finally add this to your html code:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误