Member Login

Freestyle Joomla Forums

Includes: Data

Member Login   Register

Please login or register to post on the forum

Forum Index    Board Index    Last Post   

Raymond Collins

Raymond Collins

25 September 2013, 03:59

User_ID in SQL Query

Is there a way to use the current user's User_ID in the SQL Query ?
Adam Clarke

Adam Clarke

26 September 2013, 09:57

Re: User_ID in SQL Query

Hello

There isnt a way of doing this in the current version, but its a good idea to be able to do things such as this.

I have made some changes to the code to allow the SQL statement for a SQL based data set to be parsed through the smarty parser. This allows you to modify the SQL based on the parameters passed, and using a couple of other things.

To get the user id, the query would be something like:

SELECT * FROM #__users WHERE id = {$user->id}

The above query will display an error though if the user is not logged in (as there is no record in the users table for user id 0). A work around for this would be to create a user to display information for unregistered users. Note down the user id for the user and use a query similar to

{if $user->id > 0}
SELECT * FROM #__users WHERE id = {$user->id}
{else}
SELECT * FROM #__users WHERE id = 1234
{/if}

The new version will be available later on today when testing has been completed. If you have any issue or further problems, please let me know.

Thanks
Raymond Collins

Raymond Collins

26 September 2013, 14:14

Re: User_ID in SQL Query

Wow!
Thanks for such a quick response.

Your solution will work.for me.

I will check back over tomorrow and the next day to see when the update is ready.
Adam Clarke

Adam Clarke

27 September 2013, 17:50

Re: User_ID in SQL Query

Hello

This code is available in the 2.1.1.1718 version of Includes: Data. Please let me know if there is any issues.

Thanks
kid

kid

24 October 2014, 10:25

Re: User_ID in SQL Query

SELECT id FROM #__users AS PNL WHERE id = {$user->id} 

This doesnt seem to work on the pro version
Regards
Adam Clarke

Adam Clarke

24 October 2014, 11:11

Re: User_ID in SQL Query

For this to work, you need to ensure that you have Smarty processing enabled for your SQL command (when editing the SQL, enable "Parse SQL with smarty")

I did a quick test on your SQL, and once Smarty is enabled on SQL this seems to work correctly.

Thanks

Adam Clarke
Freestyle Joomla
kid

kid

24 October 2014, 14:16

Re: Audit Message

When the Smarty option is on, testing the query returns

http://screencast.com/t/K3ZfSwRt

Does this look the same as the way you tried it?

regards
Adam Clarke

Adam Clarke

24 October 2014, 15:13

Re: User_ID in SQL Query

The query you have there should work, but unfortunately, due to how things work, there is no way of running a query preview when smarty processing is enabled.

Do you have an item template configured for this query? Try setting it to

Item: {var}

and going to the page where you have data includes setup, and seeing if there are some items output.

If you would like me to take a look at your site and get things working please let me know.

Adam Clarke
Freestyle Joomla

Vote For Us!

Please vote for our software or write a review of one of our products on the Joomla! Extensions Directory