This topic is locked
[SOLVED]

Button to display records in list based upon date

5/28/2024 11:59:48 AM
PHPRunner General questions
J
Jon_AK author

In my current app, there is a list that displays all current records. I added a button to the list that when clicked will display just the records for the current date but not having any success getting it to work. I am quite familiar with SQL but not with Javascript.
The button I created is a custom 3 part button & entered the SQL code into the server section of the button SELECT * FROM [tablename] WHERE [datefield] = CURRENT_DATE; but obviously there is a lot missing since the resulting display does not change. This is a postgres database & the SQL statement works fine when directly addressing the database using PGAdmin. Appreciate any help....

M
MikeT 5/28/2024

You could add an "additional WHERE tab" in the query screen in phprunner.
Then either forget about the button and just show the tab, or hide the tab by default and show it with the button.

C
cristi 5/28/2024

When you say: "entered the SQL code into the server section of the button" you mean that litterally?
Because in the server section you enter PHP code and not SQL queries as is - but called from PHP code...
Mike gave you a great tip - you should follow his advice.

C
Chris Whitehead 5/28/2024

@Jon_AK I would look at what MikeT has said, that's the quickest solution and doesn't need any JS.

G
George K 5/29/2024

@Jon_AK, I have done something similar on my app.

What I did, was to pass the filter for the current date on my url as a query parameter

  1. add a button on your list page


  2. clear everything on the Client Before section


  3. On the Server section, type $result["txt"] = date("d/m/Y") ; This will pick up the current date


  4. On the Client after, add

    var urltoday = "**pagenamexxxx_list**.php?q=(**DateFieldname**~equals~"+result["txt"] +"~date2)&f=all"
    location.href = urltoday;
    replace pagenamexxxx with your page name and DateFieldname with the date field name

J
Jon_AK author 5/29/2024

You could add an "additional WHERE tab" in the query screen in phprunner.

Thanks Mike, appreciate your time. That does work although haven't tried hiding / restoring the tab, still finding my way around PHPR.

J
Jon_AK author 5/29/2024

What I did, was to pass the filter for the current date on my url as a query parameter
replace pagenamexxxx with your page name and DateFieldname with the date field name

Thanks George for your reply, appreciate your time. Still finding my way in PHPR. Looked breifly before sending a reply but not sure where the correct place is to look for the page name. Also, I'm assuming the DateFieldname is the field name from the database, yes?

G
George K 5/29/2024

Don't worry Jon_AK

The page name would usually be the name of the table that you are using for your list page. When you build the app, and view it on browser you can easily get the exact name from the address bar. Correct, the DateFieldname is the exact name of the date field in your database.

img alt

This is how my address looks like. transfers is the name of the table and TransferDate is the name of the field.

Best
George

J
Jon_AK author 5/30/2024

"The page name would usually be the name of the table that you are using for your list page. When you build the app, and view it on browser you can easily get the exact name from the address bar."

George,
That worked as advertised, just had to change the Y/m/d to m/d/y as apparently either Postgres or PHPR didn't like the formatting with the Date type field in the table. Thanks for your effort.