I would do this in a DB view that you query or a repeat server-side. Deliver the time difference to the client as a value in each of the entries in the array
Yes, I would agree… an app with Wappler is waaaaay faster if you use database views to deliver all the info you need and use the front end just to display it!
Not exactly sure what your desired result is but I can tell you what you’ve done:
Your condition says, only do this for the logged in user if their primary id is 1…so only one possible user.
You are then doing a query of your database and then attempting to repeat only the first row. I’m assuming you actually want to repeat get_log instead as it will be an array of values. Once you do that you’ll be able to select the value you are looking for inside the repeat.
The condition is there so only the admin (user 1) can engage with the server connect (extra security step) – its not the point here, should have taken it out for this example.
What I want to achieve is as described in my initial post:
I have a repeater that pulls a list of entries from a DB which include a DATETIME.
Per entry I want to calculate the time difference with the previous entry.
This is very easy to do in JS with a FOR loop etc.
But wanted to do this purely in Wappler, and in the server-side (as kindly suggested by @bpj and @Antony).
They made it sound easy ;), but I can’t seem to get the logic of the repeater and how I can call back a previous entry.
I am a bit lost here… so any suggestions (or existing tutorials that deal with similar issues) very welcome!
Hey @ant… (Great name!)
I do this kinda thing in a server action using a repeat and a session variable to store the time from then previous loop… I hope that helps!
create $_SESSION s_last_datetime;
s_last_datetime = '';
repeat on your data
compare s_last_date_time with this_datetime
Do what you need to do;
s_last_datetime = this_datetime;
The session variable value is global so will be retained for the next run around the loop.