Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:37:14+00:00 2026-05-31T19:37:14+00:00

Just starting out, this should be a simple one but I haven’t been able

  • 0

Just starting out, this should be a simple one but I haven’t been able to find a good source, especially with the 1.5 to 1.6/1.7/2.5 changeover.

Building a component and among other issues keep running into syntax issues.

For example, here’s one way I’m building a query:
[TYPE 1]

$query->SELECT('u.id as UserID
    , u.name AS Name
    , uppi.profile_value AS Hair
    , uppi2.profile_value AS Height
    ');
$query->FROM (' #__users AS u');
$query->LEFTJOIN (' #__user_profiles AS uppi ON u.id = uppi.user_id AND uppi.ordering = 1 ');
$query->LEFTJOIN (' #__user_profiles AS uppi2 ON u.id = uppi2.user_id AND uppi2.ordering = 2 ');
$query->GROUPBY (' u.id
    , u.name
    , uppi.profile_value
    ');

Another way:
[TYPE 2]

$query->SELECT('u.id as UserID
    , u.name AS Name
    , uppi.profile_value AS Hair
    , uppi2.profile_value AS Height
    ')
->FROM (' #__users AS u')
->LEFTJOIN (' #__user_profiles AS uppi ON u.id = uppi.user_id AND uppi.ordering = 1 ')
->LEFTJOIN (' #__user_profiles AS uppi2 ON u.id = uppi2.user_id AND uppi2.ordering = 2 ')
->GROUPBY (' u.id
    , u.name
    , uppi.profile_value
    ');

Confusing part about both of those is that mysql calls like “LEFTJOIN” are one word instead of two. So then if I want to use INSERT…ON DUPLICATE KEY UPDATE I’m totally lost.

Here’s a third:
[TYPE 3]

$query->SELECT('u.id as UserID
    , u.name AS Name
    , uppi.profile_value AS Hair
    , uppi2.profile_value AS Height
    ');
$query->FROM (' #__users AS u');
$query->JOIN ('LEFT', ' #__user_profiles AS uppi ON u.id = uppi.user_id AND uppi.ordering = 1 ');
$query->JOIN ('LEFT', ' #__user_profiles AS uppi2 ON u.id = uppi2.user_id AND uppi2.ordering = 2 ');
$query->GROUPBY (' u.id
    , u.name
    , uppi.profile_value
    ');
$query->ORDER ('u.name ASC');

This is another way I’ve seen queries built but can’t get to work [EDITED – working now, thanks @cppl!]
[Type 4]

$query= "SELECT `u`.`id` as UserID
    , `u`.`name` AS Name
    , `uppi`.`profile_value` AS Hair
    , `uppi2`.`profile_value` AS Height
FROM `#__users` AS u
LEFT JOIN `#__user_profiles` AS uppi ON `u`.`id` = `uppi`.`user_id` AND `uppi`.`ordering` = 1 
LEFT JOIN `#__user_profiles` AS uppi2 ON `u`.`id` = `uppi2`.`user_id` AND `uppi2`.`ordering` = 2
    ";

I’ve gone through the Joomla MVC tutorial and Lynda…neither one really addresses this beyond “here’s some code – PLOP.”

References:
    --//www.theartofjoomla.com/home/9-developer/135-database-upgrades-in-joomla-16.html
    --//stackoverflow.com/questions/8467858/joomla-1-7-db-query-does-not-work-when-query-has-an-ampersand
    --developer.joomla.org/standards/ch03s10.html
    --forum.joomla.org/viewtopic.php?p=2506722
    --forum.joomla.org/viewtopic.php?p=1200668
    --docs.joomla.org/API16:JDatabaseQuery
    --//fsadventures.com/2011/01/some-basic-joomla-database-call-functions/
    --//www.sourcecodester.com/php/3863/updating-multiple-rows-mysql-using-php.html
    --//stackoverflow.com/questions/7047471/mysql-query-syntax-error

Questions:

1) Are there any differences between these?

2) Is there a reason to use one method over another?

3) Is there a good source for learning different ways of building these? I’ve searched for hours and haven’t found anything comprehensive.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:37:15+00:00Added an answer on May 31, 2026 at 7:37 pm
    1. Your type 1,2 & 3 are using the newer JDatabaseQuery object, whereas type 4 is using the older style to set the query to an SQL string.
    2. If type 4 isn’t working do you get an SQL error? (Have you turned on Joomla’s debug mode so you can get the SQL error dumped out with the app profile?)
    3. JDatabaseQuery is used to provide the abstraction required to support multiple SQL databases rather than just mySQL, thats why the $query object has functions like select(),where(),join(), etc…
    4. Remember that the ->leftJoin() is a PHP call to the JDatabaseQuery function called leftJoin() and therefore must be one word ie. it can’t be two.
    5. leftJoin() actually just calls join('LEFT',$conditions) so it’s a readability implementation more than a functional difference.
    6. So, types 1,2 & 3 are effectively the same they’re just have different degrees of readability (eg. IMHO type 2 & 3 are harder to read and maintain than type 1).

    You seem to have found all the online sources for Joomla! documentation, apart from the Joomla! Google Groups (CMS Dev, General Dev and Platform Dev).

    The only other source is Andrew Eddies “Learn the Art of Joomla!“. I haven’t used Andrew’s stuff myself but I’ve heard lots of good things about it a the last Joomla! Day I attended.

    Edit
    Based on the error I would say it’s because you have the identifier u.id encased as one identifier. Try something like:

    SELECT `u`.`id` AS "UserID" FROM `#__users` AS `u`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is quite noobish to you, but I'm just starting out to
I am just starting out C++, so sorry if this is a dumb question.
This should be simple but I'm a noob and I can't for the life
I think this may be a very simple question, but I am only just
I have been all over this one, and I am just plumb stuck. I
I'm just starting out learning ASP.NET MVC 3. I've been going through the Music
I know this should be fairly easy but I can't quite figure it out
I'm just starting out in JSF, looks awesome, but I can't seem to figure
I'm just starting out learning python (for webapp usage) but I'm confused as to
Just starting out in asp.net. Have just created a login.aspx page in my site

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.