Skip to Content Skip to Menu

[SOLVED] Relate query results to user

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
2 years 11 months ago - 2 years 11 months ago #326955 by galanopd
[SOLVED] Relate query results to user was created by galanopd
I am using this in a query field and I get all the rating values from #__vreview_review table correctly.
How can I make each result to be visible to the correct user's profile?
I tried substitution like sub.`[user_id]` but didn't work
Code:
SELECT rev.`rating` FROM `#__vreview_review` AS rev JOIN `#__users` AS u ON rev.`page_title` = u.`username` JOIN `#__cbsubs_subscriptions` AS sub ON REGEXP_SUBSTR(rev.`xml`, '[0-9]+') = sub.`user_id` WHERE rev.`profileid` = 2 AND u.`id` = sub.`user_id`
Last edit: 2 years 11 months ago by beat. Reason: Added [SOLVED] tag to subject

Please Log in or Create an account to join the conversation.

  • beat
  • beat
  • OFFLINE
  • Posts: 2169
  • Thanks: 463
  • Karma: 352
2 years 11 months ago #326962 by beat
Replied by beat on topic Relate query results to user
[user_id] is the right substitution for the user-id.

Here an example of a query from our Demo site, counting number of articles of users:
Code:
SELECT COUNT(*) FROM `#__content` WHERE `created_by`='[user_id]' AND `state` = '1';

Please also see our videos about CB Query field:
www.youtube.com/playlist?list=PLp0puRITgC7MM9iP9FooKB1qk8f5MLWVp

You can also check the Demo site (Demo menu) at top for examples, in front for result in administration for the corresponding settings.

Beat - Community Builder Team Member

Before posting on forums: Read FAQ thoroughly -- Help us spend more time coding by helping others in this forum, many thanks :)
CB links: Our membership - CBSubs - Templates - Hosting - Forge - Send me a Private Message (PM) only for private/confidential info

Please Log in or Create an account to join the conversation.

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
2 years 11 months ago #326972 by galanopd
Replied by galanopd on topic Relate query results to user
I made the query even more simple but when I do [user_id], it brings no value on the profile.
When I use sub.`user_id`then all users show the same rating.
Code:
SELECT rev.`rating` FROM `#__vreview_review` AS rev JOIN `#__cbsubs_subscriptions` AS sub ON REGEXP_SUBSTR(rev.`xml`, '[0-9]+') = sub.`[user_id]` WHERE rev.`profileid` = '2'

Please Log in or Create an account to join the conversation.

  • beat
  • beat
  • OFFLINE
  • Posts: 2169
  • Thanks: 463
  • Karma: 352
2 years 11 months ago #326977 by beat
Replied by beat on topic Relate query results to user
Your SQL query syntax is not right. You can't use sub.'234' in the syntax.

Test your SQL query in a SQL tool, like PhpMyAdmin first, using a real user id. Once you get the result you want, replace the numeric user id you used to develop your query by [user_id] in CB Query Field.

I'm trying to understand what your query wants to achieve, and don't know this reviews component, nor its table, so it's guesswork, but my guess is that something like one of the following could work depending on what you want to achieve and the structure of the review table:
Code:
SELECT rev.`rating` FROM `#__vreview_review` AS rev JOIN `#__users` AS u ON rev.`page_title` = u.`username` JOIN `#__cbsubs_subscriptions` AS sub ON REGEXP_SUBSTR(rev.`xml`, '[0-9]+') = sub.user_id WHERE rev.`profileid` = [user_id] AND u.`id` = sub.`user_id`

or
Code:
SELECT rev.`rating` FROM `#__vreview_review` AS rev JOIN `#__users` AS u ON rev.`page_title` = u.`username` JOIN `#__cbsubs_subscriptions` AS sub ON REGEXP_SUBSTR(rev.`xml`, '[0-9]+') = sub.user_id WHERE rev.`profileid` = 2 AND u.`id` = sub.`user_id` AND u.`id` = [user_id]

Please ask the developer of the review component for help for the right query to get the result you want, we can't give support for third-party components.

Beat - Community Builder Team Member

Before posting on forums: Read FAQ thoroughly -- Help us spend more time coding by helping others in this forum, many thanks :)
CB links: Our membership - CBSubs - Templates - Hosting - Forge - Send me a Private Message (PM) only for private/confidential info
The following user(s) said Thank You: galanopd

Please Log in or Create an account to join the conversation.

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
2 years 11 months ago #326982 by galanopd
Replied by galanopd on topic Relate query results to user
The
Code:
AND u.`id` = [user_id]
did the work.

Thank you Beat, very helpful

Please Log in or Create an account to join the conversation.

  • beat
  • beat
  • OFFLINE
  • Posts: 2169
  • Thanks: 463
  • Karma: 352
2 years 11 months ago #326987 by beat
Replied by beat on topic [SOLVED] Relate query results to user
Awesome!
Thanks for sharing the solution witth the community!
Marking as solved.

Beat - Community Builder Team Member

Before posting on forums: Read FAQ thoroughly -- Help us spend more time coding by helping others in this forum, many thanks :)
CB links: Our membership - CBSubs - Templates - Hosting - Forge - Send me a Private Message (PM) only for private/confidential info
The following user(s) said Thank You: galanopd

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum