Skip to Content Skip to Menu

Newbie alert - trying to create a CB Query field with a link

  • zorroson
  • zorroson
  • OFFLINE
  • Posts: 6
  • Thanks: 1
  • Karma: 1
7 years 4 months ago - 7 years 4 months ago #294736 by zorroson
Hi all,

All new to CB but have worked with Joomla for 8 years, trying to figure out a way to create a small customer relations app, using CB.

For this I need to look up a customer in a non-CB table in MySQL and do this using a CB Query Field with the following query:
Code:
SELECT name, id FROM `#__eaci_customers` ORDER BY `name`

This query work fine, and if I don't do anything else, I get a fine list with the customers. However I need to be able to click a hyperlink on each customers name, and have therefor tried editing the "Profile Value Layout" to the following:
Code:
<div><a href="index.php/customers/[column_id]">[column_name]</a></div>

I get a fine link alright, however the [column_id] and [column_name] are not substituted with the values from my query.

I've tried using just [id] and [name], and then the substitution works, but give me the logged in users id and name.

So - whats the correct syntax to the the values in my link substituted with the values from my query?

Cheers

Edit: Using CB Query 5.0.4 (plug_cbqueryfield_5.0.4+build.2017.04.27.01.40.36.d2d5b6dda)
Last edit: 7 years 4 months ago by zorroson. Reason: Added [SOLVED] tag to subject

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48448
  • Thanks: 8280
  • Karma: 1443
7 years 4 months ago #294744 by krileon
Your query doesn't look specific to a user. Are you sure you want to output every row in that table as a field? I'm guessing there should be a WHERE statement added to it to reduce the results down to be more specific to that user? At any rate the HTML is fine it's just in the wrong spot. Edit your query field and under Parameters > Display change Output to "Multiple Rows" then place your HTML in Row. If you're expecting a single row then set Output to "Single Row" then set Columns to "Multiple Columns" and Display to "Custom" now place your HTML in Custom.


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.

  • zorroson
  • zorroson
  • OFFLINE
  • Posts: 6
  • Thanks: 1
  • Karma: 1
7 years 4 months ago - 7 years 4 months ago #294751 by zorroson
Kyle,

Thanx for your response!
You are right - I need to narrow the query down to give me only the customers belonging to the specific user!

Works perfect after following your guidelines above!
Appreciate it very much!

Cheers
Last edit: 7 years 4 months ago by zorroson.

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

  • zorroson
  • zorroson
  • OFFLINE
  • Posts: 6
  • Thanks: 1
  • Karma: 1
7 years 4 months ago - 7 years 4 months ago #294755 by zorroson
Hi again,

Have to ask one more question..

I've now changed the query to:
Code:
SELECT name, id FROM `#__eaci_customers` WHERE `id`='[cb_customers]' ORDER BY `name`

Also changed Output to "Multiple Rows" and placed the following in "Rows"
Code:
<div><a href="index.php/kunder/kunder/[column_id]">[column_name]</a></div>

If just one customer name and id is returned from the selected record, it works and show this perfectly. However - a client can have more than one customer, and if thats the case, only the first value (customer) is shown as a result of the above output - not the rest...

When I edit the customer information on a client, I do this by using the "Query Drop Down (Multi-select)". When selecting multiple customers, this is stored in a "customer" column in comprofiler table, in the format "4|*|1|*|3|*|5" each representing a customer id from "#__eaci_customers".

Question is - how do I format the query and output above, show all customers id & names registered for the user? I thought this was what the selection of "Multiple Rows" was supposed to do for me - ie. run the query for each value in the "cb_customers" column on the selected record?

Hope you can follow me, as I feel this is described somewhat more complex than I intended :)

Cheers ;)
Last edit: 7 years 4 months ago by zorroson.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48448
  • Thanks: 8280
  • Karma: 1443
7 years 4 months ago #294767 by krileon
You'll have to use SQL functions to format the |*| delimitered multiselect values so you can match it.

Code:
SELECT name, id FROM `#__eaci_customers` WHERE FIND_IN_SET( `id`, REPLACE( '[cb_customers]', '|*|', ',' ) ) > 0 ORDER BY `name`

There are of course several alternatives like LIKE statements with wildcards or even REGEX.


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.
The following user(s) said Thank You: zorroson

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

  • zorroson
  • zorroson
  • OFFLINE
  • Posts: 6
  • Thanks: 1
  • Karma: 1
7 years 4 months ago #294771 by zorroson
Krileon,

I love you man - thanx a lot, it makes totally sense and works perfectly!!

Cheers
The following user(s) said Thank You: krileon

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

Moderators: beatnantkrileon
Powered by Kunena Forum