search

Home  >  Q&A  >  body text

Regarding the problem of repeatedly executing sql

Db:table('shop_goods')->count();

Here I executed one more Db query to query the total number of paging. I feel that the query efficiency is affected. Can I compare it with the query data set results? Share one? Just execute Db:table('shop_goods') once.

麦子麦子1168 days ago1105

reply all(4)I'll reply

  • autoload

    autoload2021-11-29 10:56:24

    Didn’t you take out the result set directly? Check the length of the result set directly, and then divide it by how many pages are divided into. Once divided, the number of pages will come out. If it’s troublesome for you, just use the method provided by tp

    reply
    0
  • 麦子

    Yes, but if the result set is conditionally filtered, for example, there are 10 pieces of data in total, and there are only 3 pieces after filtering, then the length of the output result set is 3, which is wrong~

    麦子 · 2021-11-29 21:49:51
  • autoload

    autoload2021-11-29 10:41:15

    Yes, it just depends on how you like to use it

    reply
    0
  • 麦子

    Boss, please write a code explanation.

    麦子 · 2021-11-29 10:49:37
  • Cancelreply