Okay
  Public Ticket #2685280
MYSQL Query Failing
Closed

Comments

  • Alex started the conversation

    I am attempting to create a wpDataTable using a typical SQL command.  I have WP datatables linked to my MYSQL database table, and I am interested in getting the most recent 5 entries in a table.  In my database I use the following SQL command to do this:

    SELECT * FROM `Motorx1` ORDER BY `Motorx1`.`id` DESC LIMIT 5

    However, this is not working when I try to use this query to create a table in WPdatatable.  I can use:

    SELECT * FROM `Motorx1` ORDER BY `Motorx1`.`id`

    but this gets me all of the entries in the table and I am not interested in this.

  •  2,507
    Aleksandar replied

    Hello Alex

    Thank you for your purchase.

    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 the statement automatically when users trigger the sorting on the front-end, and having it in the initial statement may cause the table to crash.

    You can use this query:

    SELECT * FROM Motorx1 ORDER BY id DESC LIMIT 5
    

    if you disable "server-side processing" on the "Data Source" tab above the table:

    7042314750.png


    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

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

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables