Skip to Content Skip to Menu

[SOLVED] MySQL Field vs. CB Query

  • fraenk
  • fraenk
  • OFFLINE
  • Posts: 4
  • Thanks: 1
  • Karma: 0
9 years 6 months ago - 9 years 6 months ago #263714 by fraenk
[SOLVED] MySQL Field vs. CB Query was created by fraenk
In CB 1.9 I used the MySQL-Field-Plugin to calculate the distance to a user.
I want to do this in CB2, but the MySQL Field Plugin is not compatible.

The SQL-Query I used in CB1.9 was:
Code:
SELECT round( 6378.137*ACOS( SIN(u.cb_plug_lat / 180 * PI()) * SIN(v.cb_plug_lat / 180 * PI()) + COS(u.cb_plug_lat / 180 * PI()) * COS(v.cb_plug_lat / 180 * PI()) * COS(v.cb_plug_lng / 180 * PI() - u.cb_plug_lng / 180 * PI())) ) FROM `#__comprofiler` as u, `#__comprofiler` as v WHERE u.id={USERID} and v.id={VIEWERID}

Is the CB Query Plugin the right choice to get the same result?
If yes, how can I substitute {USERID} and {VIEWERID} in CB Query?
Last edit: 9 years 6 months ago by krileon.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48478
  • Thanks: 8282
  • Karma: 1443
9 years 6 months ago - 9 years 6 months ago #263730 by krileon
Replied by krileon on topic MySQL Field vs. CB Query
CB Query Field uses standard substitution format. See the below tutorial for substitution usage information.

www.joomlapolis.com/support/tutorials/107-use-cases/18353-using-substitutions-throughout-cb

Specifically for user id you can use the below.

Displayed User:
[user_id] or [cb:userdata field="user_id" user="#displayed" /]

Viewing User:
[cb:userdata field="user_id" user="#me" /]

Ensure you surround substitutions in single quotes to avoid issues where nothing is returned causing a SQL error (e.g. '[user_id]').


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: 9 years 6 months ago by krileon.
The following user(s) said Thank You: fraenk

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

  • fraenk
  • fraenk
  • OFFLINE
  • Posts: 4
  • Thanks: 1
  • Karma: 0
9 years 6 months ago #263745 by fraenk
Replied by fraenk on topic MySQL Field vs. CB Query
Works perfectly ;)

Thank you for your quick response

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

Moderators: beatnantkrileon
Powered by Kunena Forum