- Posts: 6
- Thank you received: 0
Get user id for SQL custom field
- Connor Walsh
- Topic Author
- Offline
- New Member
-
Less
More
8 years 8 months ago #86237
by Connor Walsh
Get user id for SQL custom field was created by Connor Walsh
I'm using event booking for users to register their kids for summer camps. Each user has already entered their child's information on the website and this is stored in a database table. The children are linked to their parent via the current users id
My custom field is just going to be a select list with the children's names. I planned to do this with the SQL custom field type, with the query "SELECT child_name AS value, child_name AS text FROM #__child_master WHERE parent_id = $user_id"
I'm just not sure how to get the current user_id in that sql statement. If it were php I could just do JFactory::getUser()->id, but trying that in my statement didn't work.
Any ideas on how I can do this?
Thanks!
My custom field is just going to be a select list with the children's names. I planned to do this with the SQL custom field type, with the query "SELECT child_name AS value, child_name AS text FROM #__child_master WHERE parent_id = $user_id"
I'm just not sure how to get the current user_id in that sql statement. If it were php I could just do JFactory::getUser()->id, but trying that in my statement didn't work.
Any ideas on how I can do this?
Thanks!
Please Log in or Create an account to join the conversation.
- Russell Noble
- Offline
- Premium Member
-
Less
More
- Posts: 103
- Thank you received: 5
8 years 8 months ago #86244
by Russell Noble
Replied by Russell Noble on topic Get user id for SQL custom field
I've submitted code for something similar which was to allow the event id to be used. It could easily be modified to let the user id be used.
If you're up to modification you can edit administrator/components/com_eventbooking/libraries/rad/form/field/sql.php and add a string substitution in. I've set mine up so [EVENT_ID] has the ID substituted into the query, the user id would be just as easy and I've thought about adding it.
FYI we have SQL as a FEE field and the event ID is used in the query. I've got the code working to allow it to be quanity field as well but need to submit that in github.
If you're up to modification you can edit administrator/components/com_eventbooking/libraries/rad/form/field/sql.php and add a string substitution in. I've set mine up so [EVENT_ID] has the ID substituted into the query, the user id would be just as easy and I've thought about adding it.
FYI we have SQL as a FEE field and the event ID is used in the query. I've got the code working to allow it to be quanity field as well but need to submit that in github.
Please Log in or Create an account to join the conversation.
- Connor Walsh
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 6
- Thank you received: 0
8 years 8 months ago #86245
by Connor Walsh
Replied by Connor Walsh on topic Get user id for SQL custom field
Yeah if you could send me that code that would be awesome!
Please Log in or Create an account to join the conversation.
- Russell Noble
- Offline
- Premium Member
-
Less
More
- Posts: 103
- Thank you received: 5
8 years 8 months ago #86249
by Russell Noble
Replied by Russell Noble on topic Get user id for SQL custom field
This is my raw code, you should only need to change the getOptions() function, I've added some extra stuff, but for what you want you should be able to modify it.
*usual disclaimers*
*usual disclaimers*
Attachments:
The following user(s) said Thank You: Tuan Pham Ngoc
Please Log in or Create an account to join the conversation.
- Connor Walsh
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 6
- Thank you received: 0
8 years 8 months ago #86291
by Connor Walsh
Replied by Connor Walsh on topic Get user id for SQL custom field
This worked perfectly, thanks so much!
Please Log in or Create an account to join the conversation.
- Carmen Peleato
- Offline
- New Member
-
Less
More
- Posts: 7
- Thank you received: 0
8 years 3 months ago #92636
by Carmen Peleato
Replied by Carmen Peleato on topic Get user id for SQL custom field
Hi All
We are in the same situation.
Our association is composed of families with multiple children (twins, triplets ..). In our free activities only the children of each family can be registered, and they are always the same.
We need to know how to find the name of a child by the membership number.
In the sql Query we are testing, we look for the child's name and add the year and month of birth (some activities depend on the child's age)
I do not program in php and I do not know how to modify the sql.zip file that I have added in this post to get current user_id
Our SQL Query we use:
SELECT CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as value, CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as text from `#__comprofiler` WHERE cb_numerodesocio = 1747 ( we need to get here current loged $user_id )
This Query gets this Result: Carolina, 2009-03 ( for example)
With this php (php.zip) we can select from a list, but we can´t add a second line on SQL Query (field default values) (dont work) to make a list from diferents Childs from a family.
We have other problems that we do not know how to solve, but i will open another topic to ask about.
Thanks in advance and sorry for my English
We are in the same situation.
Our association is composed of families with multiple children (twins, triplets ..). In our free activities only the children of each family can be registered, and they are always the same.
We need to know how to find the name of a child by the membership number.
In the sql Query we are testing, we look for the child's name and add the year and month of birth (some activities depend on the child's age)
I do not program in php and I do not know how to modify the sql.zip file that I have added in this post to get current user_id
Our SQL Query we use:
SELECT CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as value, CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as text from `#__comprofiler` WHERE cb_numerodesocio = 1747 ( we need to get here current loged $user_id )
This Query gets this Result: Carolina, 2009-03 ( for example)
With this php (php.zip) we can select from a list, but we can´t add a second line on SQL Query (field default values) (dont work) to make a list from diferents Childs from a family.
We have other problems that we do not know how to solve, but i will open another topic to ask about.
Thanks in advance and sorry for my English
Please Log in or Create an account to join the conversation.
- Carmen Peleato
- Offline
- New Member
-
Less
More
- Posts: 7
- Thank you received: 0
8 years 3 months ago #92687
by Carmen Peleato
Replied by Carmen Peleato on topic Get user id for SQL custom field
Any help Please?
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
8 years 3 months ago #92688
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Get user id for SQL custom field
Sorry. I have been so busy today and could not look at this question and answer. I will look at it on tomorrow (too tired now to look at it)
Tuan
Tuan
Please Log in or Create an account to join the conversation.
- Tuan Pham Ngoc
- Offline
- Administrator
-
8 years 3 months ago #92746
by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Get user id for SQL custom field
Hello
Please try the solution below:
1. Get this file, unzip it, upload it to administrator/com_eventbooking/libraries\rad\form\field folder
2. Then in the SQL command, you can use the tag [USER_ID] . It will be replaced with ID of the logged in user
Actually, I think there is still problem. That will only works when users to register. When admin view the registration record for example, it will be replaced with ID of admin, so we will still have problem
Need better solution. Will try to have a solution for you on Monday
Regards,
Tuan
Please try the solution below:
1. Get this file, unzip it, upload it to administrator/com_eventbooking/libraries\rad\form\field folder
2. Then in the SQL command, you can use the tag [USER_ID] . It will be replaced with ID of the logged in user
Actually, I think there is still problem. That will only works when users to register. When admin view the registration record for example, it will be replaced with ID of admin, so we will still have problem
Need better solution. Will try to have a solution for you on Monday
Regards,
Tuan
- Carmen Peleato
- Offline
- New Member
-
Less
More
- Posts: 7
- Thank you received: 0
8 years 3 months ago #92747
by Carmen Peleato
Replied by Carmen Peleato on topic Get user id for SQL custom field
Hi Tuan
Thanks for the code. Thats work perfect
SELECT CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as value, CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as text from `#__comprofiler` WHERE user_id = [USER_ID]
Why i cant add a second query line to add another list option? this would be perfect to get all chids from a family in only one list
Thanks for the code. Thats work perfect
SELECT CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as value, CONCAT (`cb_hijo1pm1`, ', ', LEFT(`cb_fechapartomultiple1`, 7)) as text from `#__comprofiler` WHERE user_id = [USER_ID]
Why i cant add a second query line to add another list option? this would be perfect to get all chids from a family in only one list
Please Log in or Create an account to join the conversation.
Moderators: Tuan Pham Ngoc
Support
Documentation
Information
Copyright © 2025 Joomla Extensions by Joomdonation. All Rights Reserved.
joomdonation.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.