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 7669393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:35:04+00:00 2026-05-31T15:35:04+00:00

Fledgling Joomla / PHP developer, hitting a wall understanding how to do this. Everything

  • 0

Fledgling Joomla / PHP developer, hitting a wall understanding how to do this. Everything I found searching has been for older versions of Joomla or other frameworks and so it’s all confusing the first time around.

I want to have a helper function that I can call from anywhere in my component. Basically it takes a userID input and returns their full name, let’s say hair color and height. Here’s the function:

function get_profile_info($userID) {

        $db =& JFactory::getDBO();          
        $query = $db->getQuery(true);

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


       $db->setQuery($query);   
       return $query;                   
}

I’d put this in a file called “lookups.php” within the “helpers” folder of my component…but here’s where I’m not sure what to do next. Top of lookups.php has the obligatory:

<?php defined ( '_JEXEC' ) or die;

So two questions:
1) Do I put everything in a class or keep it as a series of functions (since there will be others)?

2) How do I pass the userID and get back the values of Name, Hair, and Height in the view (view.html.php / default.php)?

Thank you!

==================================

Edit: Based on @Shaz ‘s response below here’s where I’m at (again, just starting off and trying to wrap my head around some of this):

lookups.php

abstract class LookupHelper {

        var $Name;
        var $Hair;
        var $Height;

    public function get_profile_info($userID) {
                ... 
                (same as above until the next line)

                $db->setQuery($query);
                $result=$db->loadRow();
                $Name = $result[1];
                $Hair = $result[2];
                $Height = $result[3];
        $getprofileinfo = array(Name=>$Name, Hair=>$Hair, Height=>$Height);
                $return $getprofileinfo;
           }
    }

Then in my default.php (will probably move to view.html.php):

    $getprofileinfo = Jview::loadHelper('lookups'); //got an error without this
    $getprofileinfo = LookupHelper::get_profile_info($userID);

    $Name = $getprofileinfo[Name];
    $Hair = $getprofileinfo[Hair];
    $Height = $getprofileinfo[Height];

So…it’s working – but it seems like there’s a much easier way of doing this (specifically manually creating an array then recalling by position). Thoughts?

Thank you!!

  • 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-31T15:35:05+00:00Added an answer on May 31, 2026 at 3:35 pm
    1. Create the helper class and include there all your functions:

      abstract class HelloWorldHelper
      {
      /* functions */
      }

    2. Call the function and store the result:

      $var = HelloWorldHelper::get_profile_info($thatId);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a fledgling iPhone developer, so be easy on me. I'm trying to develop
I'm the one-man dev team on a fledgling military history website. One aspect of
So I'm a computer science student and a fledgling programmer in Java. Someone asked
I'm using the Cycle plugin for use in a news-rotator. This means I'm using
I have a fledgling app under development, which I am installing to my Android
I'm a fledgling DBA dealing with some medical data. While I've not yet gotten
This shows the code that hides slides the photograph thumbails away etc when the
I have a question regarding naming conventions in C# that I don't think are
I know it is possible to integrate traditional ASP .NET into an MVC application

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.