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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:25:45+00:00 2026-05-13T20:25:45+00:00

I have an SQL query that lists the uid of all users who have

  • 0

I have an SQL query that lists the uid of all users who have a certain role:

SELECT u.uid 
FROM {users} as u, {users_roles} as ur 
WHERE u.uid = ur.uid AND ur.rid = 10 ORDER BY u.uid DESC

I need to load them all in an array as objects for listing.

I asked a question previously that left me only with the answer that what I wanted to do would be easier done without Views – so I’m going use a template file instead.
Therefore this question.

I know how to do this, but apparently my method is worth -2

This is how I want to do it:

$research['sql']   = "SELECT u.uid FROM {users} as u, {users_roles} as ur WHERE u.uid = ur.uid AND ur.rid = 10 ORDER BY u.uid DESC";
$research['sql_result'] = db_query($alumni['sql']);

// Load user objects and store in array
while($user_array = db_fetch_array($research['sql_result'])) {
  // Create user objets based on uid
  $user_obj = user_load($user_array['uid']);

  // Load profile
  profile_load_profile($user_obj);
  $research['users'][$user_obj->uid] = $user_obj;
}

Please help me with how I should do it.

  • 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-13T20:25:45+00:00Added an answer on May 13, 2026 at 8:25 pm

    Your basic approach looks fine by me, except that the call to profile_load_profile() is redundant:

    The user_load() function will invoke hook_user with operation ‘load’, and the profile module implements hook_user and calls profile_load_profile() for the load operation itself, so by the time you call it explicitly, it has already been called implicitly and you can just drop it.

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

Sidebar

Related Questions

We have a SQL query that pulls a large number of fields from many
I have an SQL query that returns all companies records ignore the ones with
I have a query that lists features, based on components status and availability SELECT
In SQL Server 2005 I have a table cm_production that lists all the code
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I have a sql query that runs super fast, around one second, when not
I have a SQL query that takes a very long time to run on
I have a SQL query that I'm trying to debug. It works fine for
I have a SQL query that I'm trying to write, but I'm not quite
I currently have a SQL query that returns a number of fields. I need

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.