• Resolved jpamado

    (@jpamado)


    Is it possible to dynamically change the WHERE clause when calling a Data Table based on a view? The scenario goes something like this:

    • There is a search form with a series of independent fields for performing date searches, 6 in total, year, month and day in duplicate, for date interval searches. This non-standard arrangement is adequate to the nature of the data – historical data, with missing information.
    • It is easy to search for any given date element, single or combined. However, the client also wants the ability to search between dates. In this case, searches will only be performed over full dates.

    I have been unable to find an elegant way of solving this need. A WHERE clause would allow me to filter between dates, but would only be needed if the user provided lower and upper dates in the search form. And also, I’m not sure about the way to supply the WHERE line in the Data Table definition with the appropriate form field references.

    Am I making this overly complex? Sorry for not providing a link to the existing solution, but is isn’t public yet.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @jpamado

    Thank you for reaching out.

    You can dynamically built your where clause. The following documentation page shows the new way of working with URL parameters and contains an example for handling optional URL arguments:
    https://wpdataaccess.com/docs/data-tables-filters/static-filters/

    Please make sure you’re using this new feature!

    The page contains the following example to check optional URL argument student_id:
    student_id = ifnull( httpPost[‘student_id’], student_id )

    You can combine multiple columns using this construction, although it gets more complex with a larger number of columns.

    Does this help?

    Thanks,
    Peter

    Thread Starter jpamado

    (@jpamado)

    Thank you so much Peter! I was missing the correct syntax on the URL arguments.

    Best regards and keep the good work on this fantastic plugin.
    jpamado

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Building a dynamic WHERE clause when calling a Data Table’ is closed to new replies.