Data query username and $Session_Name

Hi
Trying to build a MYSQL query on a table to return data where the username = $SESSION_NAME, is this possible within wappler?
so something like IF ‘username’ = ($_SESSION[‘username’]).
Tried adjusting the syntax to include{} and{{}} around ($_SESSION[‘username’]) but nothing.
Any idea anyone?
I works outside of Wrappler as normal code though?

Thanks
Michael

1 Like

Have a look at this video starting at 4 minutes and 45 seconds https://www.dmxzone.com/go/32190/dmxzone-server-connect-manual/32338/filtering-a-database-query-using-the-identity-of-the-logged-in-user

Hi Thanks,
the answer was quite simple just an adjustment in syntax, rather than {{$_SESSION[‘username’]}} , it had to be {{$_SESSION.username}}

1 Like

If you have already created your session all you need to do is add it as a Global variable (as a session) to your Server Actions Globals. Then use (select) this session variable to filter your result set accordingly.

2 Likes

Hi Dave,
Thanks that sounds like a goos idea, how do I do that exactly?
Still trying to walk my way round Wappler
Thanks

I am not sure if you want to use the identity of the logged in user but if that’s the task - this tutorial explains how to do it: Getting Details of the Logged In User and Binding them to your page - the identity is returned in server connect steps.

For any other session variable, which you want to use (generated by some other script on the page) - just add it under Globals > $_SESSION of your server action file, it will then be accessible in the data picker.

2 Likes