Skip to Content Skip to Menu

[SOLVED] How to update CB-Field based on non-CB tables?

  • ncmed
  • ncmed
  • OFFLINE
  • Posts: 31
  • Thanks: 1
  • Karma: 0
12 years 3 months ago - 12 years 3 months ago #206245 by ncmed
I have JoomlaQuiz Deluxe with the table #_quiz_r_student_quiz and the rows c_student_id and c_passed. The student id is the same id as the user id so I would think it can be used as a parameter to the query. The c_passed is holding true when the user has passed their quiz. I would like my cb_trainingpass radio button field to go from no to yes. Is this possible?

I have tried a few queries with CB Auto Actions plugin and one of the query new field plugins with no luck. This could be my not accurately writing my query though.
Last edit: 12 years 3 months ago by krileon.

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

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
12 years 3 months ago #206272 by nant

ncmed wrote: I have JoomlaQuiz Deluxe with the table #_quiz_r_student_quiz and the rows c_student_id and c_passed. The student id is the same id as the user id so I would think it can be used as a parameter to the query. The c_passed is holding true when the user has passed their quiz. I would like my cb_trainingpass radio button field to go from no to yes. Is this possible?

I have tried a few queries with CB Auto Actions plugin and one of the query new field

plugins with no luck. This could be my not accurately writing my query though.


Make sure you are using the latest CB Query field plugin.
Post versions of CB Query, CB and Joomla.

Post the query you are trying so we can comment on it.

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

  • ncmed
  • ncmed
  • OFFLINE
  • Posts: 31
  • Thanks: 1
  • Karma: 0
12 years 3 months ago #206360 by ncmed
I have used in Auto Actions ...
Code:
UPDATE #__comprofiler SET cb_trainingpass = ( SELECT c_passed FROM #__quiz_r_student_quiz WHERE #__quiz_r_student_quiz.c_student_id = #__comprofiler.user_id) WHERE EXISTS ( SELECT c_passed FROM #__quiz_r_student_quiz WHERE #__quiz_r_student_quiz.c_student_id = #__comprofiler.user_id);

... and it looks to work in the fact that I get either 0 (for not passed) or 1 (for passed). The problem is I need it to say yes or no as the field I am updating was radio buttons that had the "yes" or "no" selections. Also, there are multiple quiz's filled out so this can potentially be pulling from #__quiz_r_student_quiz.c_student_id multiple times.

Also, not sure if related, but my search field boxes do not display on front end after this update.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
12 years 3 months ago #206363 by krileon
If you just want to display the results of a query on profile use CB Query Field. No need to update an existing field. If you insist on updating an exiting field your query is not user specific; you're updating every row (not good). Don't quite understand your query.


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 or Create an account to join the conversation.

  • ncmed
  • ncmed
  • OFFLINE
  • Posts: 31
  • Thanks: 1
  • Karma: 0
12 years 3 months ago #206370 by ncmed
1) I was able to fix issue with field boxes not displaying, this was from using the "trigger" at this time, creating a javascript conflict.

2)This DOES update user specific fields. It actually grabs the information from the #__quiz_r_student_quiz table and adds it to #__comprofiler table in the proper column.

The problem I am having is it looks to selecting the first time it comes across the...
Code:
WHERE #__quiz_r_student_quiz.c_student_id = #__comprofiler.user_id

...This is actually good as not to append multiple rows, but I would like to add only if any of them contain 1. Is it possible to add query parameters for this?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
12 years 3 months ago #206374 by krileon

2)This DOES update user specific fields. It actually grabs the information from the #__quiz_r_student_quiz table and adds it to #__comprofiler table in the proper column.

Your query isn't user specific (no user id in where statement). So you're updating every user row everytime this fires and depending on the trigger being used this could be an extremely bad idea (as your userbase grows the query when get slower and slower).

I don't quite understand what you're doing with the query as it's malformed, but will try my best. Please see the below and comment further if it's what you're trying to do.
Code:
UPDATE `#__comprofiler` AS c SET `cb_trainingpass` = ( SELECT q.`c_passed` FROM `#__quiz_r_student_quiz` AS q WHERE q.`c_student_id` = c.`id` LIMIT 1 ) WHERE ( SELECT COUNT( q.`c_passed` ) FROM `#__quiz_r_student_quiz` AS q WHERE q.`c_student_id` = c.`id` ) >= 1 AND c.`id` = '[user_id]';

I don't know what "c_passed" is supposed to output, but if trainingpass is a field with specific values it likely won't do anything. If it's a text field it'd just update with that value, but again I've no idea what you're trying to do exactly. For example the query should be extended with an ORDER BY (maybe a date column) so it only gets the latest, etc..

Please understand no one here but you understand your database structure. So trying to write a custom detailed query for you is next to impossible. Please see the above example and adjust as necessary. You can also review the below MYSQL documentation and tutorials.

dev.mysql.com/doc/refman/5.6/en/index.html
www.w3schools.com/sql/default.asp


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 or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum