dtwzwmv87399 2016-10-31 09:44
浏览 30

Php Page Number in Huge Array

I'm trying to create a script that shows the content of a table and highlight an element searched by the user.

The output have to highlight the first element that is equal or greater than the searched value.

The searched value is a key of the table (varchar) I need to output just the page that contains the element and not all the data in the table (paged).

This is what I want to achieve:

  1. The user makes a search (using a web interface).
  2. The php script looks for the first element that contains the string (equal or greater) and get the page number (for example every page has 100 elements)
  3. The php script returns a paged result and shows only the data of the correct page.
  4. The user should be able to move to next or previous page from the page with the first match.

At the moment my script works as below:

  1. Get all elements of the table and put them in a associative array (the table key is the key of the array and is ordered by this attribute and is the searched element).
  2. Loop the array looking for the matching value (equal or greater).
  3. Get the position of the element in the array
  4. Get the page number of the element if every page has 100 elements
  5. call a class that is able to output a paged grid starting from the page number found in point 4 (no problems with this point).

I don't think using the recordset/array based method mentioned in point one is a good approach as it has a lot of elements (100.000) and I just need to show one page to the user. However, I'm not able to find the best approach.

Do you think that there is a way to improve this solution?

Below image is an example of what i would like to do:

Language: PHP DBMS: Sql Server

  • 写回答

2条回答 默认 最新

  • duanoucuo7045 2016-10-31 10:05
    关注

    The "better" solution depends on how much load you have on your database and on your sql server.

    Usually the sql database is quite faster picking a small range than picking a whole table. So I´d go for selecting the small range in sql each time moving to a next or previous page with SQL LIMIT.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题