dsqtl335227 2017-06-23 17:08
浏览 22
已采纳

MySQL使用LIKE和多页获取搜索的起始编号

at first, i know that this title is confusing, but, I wasn't abe to explain it better. I hop you can forgive me.

for a project, I have built a small "search". It just selects every row that is LIKE %query%. Depends on the query, there can be multiple rows. Much more than fit on one page. But with my page system, just set a limit for entry’s and only choose entry’s their id is more than (page-1)*entrysPerPage.

But in this way, I have the, absolute understandable, problem, that in the request for page 2 I got results from page 1. It's because not every result on page 1 without filter is used in page 1 when I filter. But on filtered page 2 I think, I can start again with (page-1)*entrysPerPage. Does anyone have an idea how do I can get the start number?

I hope my question is understandable

Thanks, allot

Cripi

  • 写回答

1条回答 默认 最新

  • dongyuying1507 2017-06-23 17:23
    关注

    Let

    $entryPerPage = 10;
    $page = 1;
    

    then

    $start = ($page-1)*$entryPerPage; // $start = 0;
    

    then your query is

    $query = "SELECT * FROM table_name LIMIT $start, $entryPerPage";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度