doujiang1832 2014-02-17 07:56
浏览 18
已采纳

如何为HTML,PHP,Javascript,MySQL中的搜索结果创建“页面”

Let's assume for following structure:

A table with two columns: id, name.

Let's assume the table consists of thousands of rows.

I have a search engine that allows me to search by free text.

The query I use to retrieve the data is as following:

SELECT * FROM `table` WHERE `name` LIKE '%$search%'

Let us also assume that the entire results are saved as associative array in a variable name $results.

I want to display them in a CSS designed html table (This is important because it slows the browser data loading).

Now, I have 2 options here:

Load all the thousands of results into the same page at once, and use the "display" to change between "pages".

Or,

I could with ajax for example, make a different search for each number I click that changes a the "LIMIT TAB_NUMBER*NUM_OF_RESULTS_PER_PAGE, NUM_OF_RESULTS_PER_PAGE".

Anyone got better idea?

  • 写回答

1条回答 默认 最新

  • doucheng4094 2014-02-17 08:17
    关注

    Use offset and limit in query and use pagination. you should not pull all the records because if you pull all records all data will come to page but will not display but you will display 20 or 30 records. so every time you get all records on page which is bad practise. you can use ajax also. that is good

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?