×

Error

Please login first

[SOLVED] Showing Connections - Using Substitution

11 years 11 months ago - 11 years 11 months ago #200767 by ptemper
BACKGROUND
Some profiles are people; some profiles are locations.
'People' work at 'locations'

Using CB Connections, People connect to Locations and designate a connection type of "Works At"

I want to show a line in people's profiles ...
'Fred' -- 'works at' -- 'Factory A'
Loged in User -- Connection Type -- A Different User ID's Name

After reading through the tutorials from Kyle's signature, I learnt about Substitutions

The logged in user Fred [cb:userdata field="username" user="#me" /] works at [cb:userdata field="name" user="99" /].
Where 99 is Factory A.... I just have to make that user="99" 'dynamic'

Next I read about CB Query Fields, so after much fiddling in mysqladmin, I came up with this (I am very new to SQL)
SELECT memberid
FROM `mydb_comprofiler_members`
WHERE `type` = 'Works at'
AND `referenceid` = '[user_id]'

This gave me the id number of the target location. I tested it as
Works At = [cb:userdata field="cb_worksat" /]
logged on as different users, and the number changed appropriately.

For the last step, I tried
The logged in user Fred [cb:userdata field="username" user="#me" /] works at [cb:userdata field="name" user="cb_worksat" /].
But this did not work. A blank was displayed.

I guess that cb_worksat is not resolving to a number??
I played around some more with syntax guessing but wih no luck... Sorry for the long description, but I have tried to get as far as I can by myself.

But if someone could help me along the rest of the way, that would be much appreciated.

Please Log in to join the conversation.

11 years 11 months ago #200824 by krileon
Replied by krileon on topic Re: Showing Connections - Using Substitution
You can't use a substitution in a substitution like that. You'll need to also have your query field resolve the name then that should do the trick. Example as follows.
SELECT b.`name`
FROM `#__comprofiler_members` AS a
LEFT JOIN `#__users` AS b
ON b.`id` = a.`memberid`
WHERE a.`type` = 'Works at'
AND a.`referenceid` = '[user_id]'
ORDER BY a.`membersince` DESC
LIMIT 1


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

11 years 11 months ago #200959 by ptemper
Replied by ptemper on topic Re: Showing Connections - Using Substitution
Thank You for that explanation. That makes sense now.
And also many thanks for taking the trouble to write out that SQL query. The extra time and thought for this is much appreciated.
Kind Regards,
PT

Please Log in to join the conversation.

11 years 10 months ago - 11 years 10 months ago #203421 by Lolo_als
Replied by Lolo_als on topic Re: Showing Connections - Using Substitution
This works fine.

Is there any way to get the name of the displayed connection as a link to the profile ?

Not: User Fred works at Factory A

But: User Fred works at Factory A

Please Log in to join the conversation.

11 years 10 months ago #203434 by krileon
Replied by krileon on topic Re: Showing Connections - Using Substitution
It can I suppose if you edited the select query to output that. Below should do the trick.
SELECT CONCAT( '<a href="index.php?option=com_comprofiler&task=userprofile&user=', b.`id`, '">', b.`name`, '</a>' )
FROM `#__comprofiler_members` AS a
LEFT JOIN `#__users` AS b
ON b.`id` = a.`memberid`
WHERE a.`type` = 'Works at'
AND a.`referenceid` = '[user_id]'
ORDER BY a.`membersince` DESC
LIMIT 1


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

11 years 10 months ago #203446 by Lolo_als
Replied by Lolo_als on topic Re: Showing Connections - Using Substitution
Hrrrrr... :woohoo: It works.

Thank you so much. :kiss:

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.169 seconds

Facebook Twitter LinkedIn