Okay
  Public Ticket #2538350
Sql Query Limit to 5 Rows Not Working
Closed

Comments

  • Farrell started the conversation

    Hi Admin , 

    I created a table linked to an existing data source,  using sql query, i added a LIMIT 5 .  but apparently, the limit 5  to  5 data rows on the result preview isn't working.  

    I wasn't able to figure out where can i limit the data rows to 5 in the frontend 

    reference: my sql query 

    SELECT symbol FROM `get_coin_rate_amount` WHERE fund_id = %VAR1% AND quote != 'usd' ORDER BY btc_worth DESC LIMIT 5;

    the data preview is attached. 

  •  472
    Isidora replied

    Hi Farrell,

    Thank you for your purchase.

    If your MySQL-query based wpDataTable doesn’t work correctly with server-side processing, probably this is happening because wpDataTables server has problems with parsing of the query and building new queries dynamically (rarely happens, but does sometimes). To avoid this please prepare a MySQL view (a stored query), which will return the data that you need, call it e.g. “view1” and then build a wpDataTabled based on a simple query like “SELECT * FROM view1″.

    Please note some this when working with the server-side processing feature:

    • Please do not use “LIMIT” in the SELECT statement. wpDataTables adds it automatically and it will be overridden.
    • Please do not use “ORDER BY” in the SELECT statement. wpDataTables has its own sorting engine so it makes no sense to use MySQL’s sorting, since it will be overridden. Also, server-side processing feature adds this part of statement automatically when users trigger the sorting on the front-end, and having it in initial statement may cause the table to crash.

    Also, because you can not use our placeholders in view my suggestion is to create view from query:

    SELECT symbol,fund_id FROM `get_coin_rate_amount` WHERE fund_id = %VAR1% AND quote != 'usd' ORDER BY btc_worth DESC LIMIT 5;

    and then use in our plugin like

    SELECT * FROM view_name  WHERE fund_id = %VAR1%

    and you can hide fund_id column if you don't need it.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables