douchuituo3032 2013-07-09 03:25
浏览 39
已采纳

如何在最少的处理时间内获得分页的总行数。

How can I get the total rows for pagination within the least amount of processing time?

My select SQL in products list is too complex for showing the total pages in pagination. I have to query the SQL with no limit parameter which takes too much time to process. Is there a better way to get the total records?

This is my SQL:

SELECT DISTINCT
    p.products_model,
    p.products_image,
    pd.products_name,
    p.products_quantity,
    p.products_id,
    p.products_type,
    p.master_categories_id,
    p.manufacturers_id,
    p.products_price,
    products_price_market,
    p.products_tax_class_id,
    pd.products_description,

IF (pbs.products_id, 1, 0) pdsid,

IF (
    s. STATUS = 1,
    s.specials_new_products_price,
    NULL
) AS specials_new_products_price,

IF (
    s. STATUS = 1,
    s.specials_new_products_price,
    p.products_price
) AS final_price,
 p.products_sort_order,
 p.product_is_call,
 p.product_is_always_free_shipping,
 p.products_qty_box_status,
 p.products_recommend,
 p.products_in_stock
FROM
    jy_products_description pd,
    jy_products p
LEFT JOIN jy_products_best_selling pbs ON p.products_id = pbs.products_id
AND pbs.category_id = 77,
 jy_products_to_categories p2c
LEFT JOIN jy_specials s ON p2c.products_id = s.products_id
AND s. STATUS = 1,
 jy_products_attributes pa0
WHERE
    p.products_status = 1
AND p.products_quantity > 0
AND p.products_id = p2c.products_id
AND pd.products_id = p2c.products_id
AND p.products_id = pa0.products_id
AND pd.language_id = 1
AND p2c.categories_id = 77
ORDER BY
    pdsid DESC,
    pbs.sort_by ASC,
    p.products_ordered

enter image description here

  • 写回答

1条回答 默认 最新

  • duanre4421 2013-07-09 04:02
    关注

    First use

    SELECT *
    FROM table
    WHERE
    STATUS = 1 AND
    catagory = 100
    HAVING
    quantity > 0
    ORDER BY
    sort ASC
    

    This will gain the full Query using PDO you can just COUNT the Amount you have in Total. Store that in the Session, and then finally use this.

    SELECT *
    FROM table
    WHERE
    STATUS = 1 AND
    catagory = 100
    HAVING
    quantity > 0
    ORDER BY
    sort ASC
    LIMIT #, #
    

    Combined with your Total Count, you can Divide the Count by the # Of Items your Showing on the Page. With that you can then use that to determine the number of pages. Round up of course. then simply use go about the amount limit, on each paganation that you stored in the session on your first run, this way you dont kill your calls constantly.

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

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?