Buy Now
Sign in

Display Latest Record from table

momentis , April 13 at 14:13
Answered
momentis
I would like to pull one record from a table (the latest record added) and display it. I have a full list of the files which is currently working, so I copied that as a start. The read_data function queries the records and sorts them in descending order by a field named "year_month". This displays the latest record first in the listing, as I desire. So, I copied this connection and changed the Data Settings to pull the first matching record. I assumed this would work, but it does not. I know I am missing something basic!!
H
healyhatman
You can't use "first matching record" because you need it to MATCH to something.
Try Select type: all matching records
Order by year_month/desc
Paging enabled
Page limit 1
Then when you want to use the data, it will be {var:read_data#.model.0}. Since var and all those other things are an array it's basically var["read_data#"]["model"][0].
Web developer at SkySpider.com.au
H
healyhatman
Of course this doesn't REALLY help when you have more than one row created in a month. I would consider adding a Date_created field, default value TIMESTAMP.
Web developer at SkySpider.com.au
momentis
Thanks again!!! That did it. To your second point, I do have a date_created field in the table. However, in this particular instance, my client will only have one file per time period.
Many, many thanks!
Rick
H
healyhatman
No problem.
My advice though - use the date_created field. That way if they decide to have a second file one month, you don't have to rewrite anything.
Web developer at SkySpider.com.au