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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:27:30+00:00 2026-06-05T09:27:30+00:00

I have a problem getting my data from database and foreach it. This is

  • 0

I have a problem getting my data from database and foreach it.

This is how I get data:

    $results = $db->get_results('SELECT *
    FROM `'.$db->base_prefix.'users` 
    LEFT JOIN `'.$db->base_prefix.'usermeta` ON '.$db->base_prefix.'users.id = '.$db->base_prefix.'usermeta.user_id 
    AND '.$db->base_prefix.'usermeta.meta_key=\''.'cpoints'.'\''.$extraquery.' 
    ORDER BY '.$db->base_prefix.'usermeta.meta_value+0 DESC'
    . $limit . ';'
    ,ARRAY_A);

and when I print array its something like this:

(
[0] => Array
(
[ID] => 4
[user_login] => member3
[user_name] => member3
[user_email] => member3@member.com
)

So far everything is great, but when I want to use data I get empty result,
this is how I used foreach:

foreach($results as $result){
    $user =  $result[0]['ID'];          
    $username = $result[0]['user_login'];
    $user_nickname = $result[0]['display_name'];
    $gravatar = get_avatar( $result[0]['ID'] , $size = '32' );

I echo the values (for example $user ) into tables after this and it comes out empty.

  • 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-06-05T09:27:31+00:00Added an answer on June 5, 2026 at 9:27 am

    Remove [0] from all $result references. It is already handled by foreach:

    foreach($results as $result){
       $user =  $result['ID'];          
       $username = $result['user_login'];
       $user_nickname = $result['display_name']; //shouldn't this be user_name?
       $gravatar = get_avatar( $result['ID'] , $size = '32' );
       //...
    }
    

    Also in you print_r result there’s no such field display_name.

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

Sidebar

Related Questions

I have a little problem with getting all data from SQLite database and showing
i am getting problem as i have some data in a database tabel file
I have a problem with getting jquery to retrieve results from a WCF service.
First, I had a problem with getting the data from the Database, it took
I have a dropdown list box that displays data from my database. Problem is
I have this problem getting my newly created php project on Netbeans work on
I have a problem with getting a class from an external .jar file. I
I have made the following code to retrive data from SQLite database. public Cursor
Im using ajax to load some data from a mysql database... my problem is,
I am getting data from a database through AJAX and appending tags to a

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.