Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount on memberships! Get 20% off now with code SPOOKY-2024!

Mysql query

11 years 7 months ago - 11 years 7 months ago #222289 by edmundcheong
Mysql query was created by edmundcheong
CB doesn't store names in jos_comprofiler, only data.. Names are stored in jos_users..

How do write a SQL query to display the data below with the condition (WHERE) cb_sex = male.. I believe I need to use a join command?

ID, NAME, cb_address, cb_postcode, cb_sex
123, John Doe, 25th Avenue, 564VBG, male
Last edit: 11 years 7 months ago by edmundcheong.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48459
  • Thanks: 8280
  • Karma: 1443
11 years 7 months ago - 11 years 7 months ago #222315 by krileon
Replied by krileon on topic Mysql query
You don't need a query field for this at all. Just use a delimiter field. Example as follows.

[cb:if cb_sex="male"]
[user_id], [name], [cb_address], [cb_postcode], [cb_sex]
123, John Doe, 25th Avenue, 564VBG, male
[/cb:if]

You can find more on substitution usage at the below tutorial.

www.allmysocials.com/directory/tutorials/item/233-substitution-usage

Aside from that no, you don't need to do a JOIN; just concat firstname, middlename, and lastname to give you name. You can also use [name] directly in your query if you wanted.


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.
Last edit: 11 years 7 months ago by krileon.

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

11 years 7 months ago #222364 by edmundcheong
Replied by edmundcheong on topic Mysql query
Sorry I think my question wasn't clear.

I need to do a query as I need to generate a list of users on my site.. and the thing is that the names and data is on different table..

I need to do a MYSQL query and export it to MS Excel..

So i am working something like:

SELECT `id` , `NAME` , `cb_addressline1` , `cb_addressline2` , `cb_postcode` , `cb_town` , `cb_state` , `cb_telephone`
FROM `jos_comprofiler` , `jos_users`
WHERE `cb_postcode` = 'XYZ123'

Can seem to get it right..

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

11 years 7 months ago #222366 by edmundcheong
Replied by edmundcheong on topic Mysql query
I tried something like this too..

SELECT `jos_users.id` , `jos_comprofiler.id`
FROM `jos_users` JOIN `jos_comprofiler`
ON jos_users.id = jos_comprofiler.meterid
GROUP BY jos_user.meterid

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48459
  • Thanks: 8280
  • Karma: 1443
11 years 7 months ago #222415 by krileon
Replied by krileon on topic Mysql query
You can CONCAT_WS the first, middle, and last names or JOIN the _users table. See the below SQL tutorial regarding JOINs.

www.w3schools.com/sql/sql_join.asp

See the below MYSQL documentation for CONCAT_WS usage.

dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_concat-ws


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