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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:07:06+00:00 2026-06-12T19:07:06+00:00

Im trying to get in Array that contains the results from a MYSQL query.

  • 0

Im trying to get in Array that contains the results from a MYSQL query.
I have 2 ids stored in the table hitlist user_id and mark_id
they need to join in the table users to retrieve there usernames that match there id’s and in the future other variables.

i have this working in a weird way and was hopeing to get this working in a more efficent simple way similar to this

$Hitlists = $db->query("SELECT * FROM hitlist JOIN users ON hitlist.user_id = users.id AND hitlist.mark_id = users.id")->fetchAll();

This is the code i have that is working…for now it looks like it might give me problems later on.

<?php
$index = 0;
$Hitlists = array();
$st = $db->query("SELECT * FROM hitlist JOIN users ON hitlist.user_id = users.id")->fetchAll();
$sth = $db->query("SELECT * FROM hitlist JOIN users ON hitlist.mark_id = users.id")->fetchAll();

foreach($st as $id) 
{
    $Hitlists[] = $id;
}

foreach($sth as $id) 
{
        $Hitlists[$index]['markedby'] = $id['username'];
        $Hitlists[$index]['mark_id'] = $id['mark_id'];
        $index++;
}
  • 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-12T19:07:07+00:00Added an answer on June 12, 2026 at 7:07 pm

    The way you are joining the table is wrong. You can get the exact records you want, you need to join users table twice to get the username of each ID

    SELECT  a.*, 
            b.username User_name,
            c.username mark_name      
    FROM    hitlist a
            INNER JOIN users b
                ON  a.user_id = b.id 
            INNER JOIN users c
                ON  a.mark_id = c.id
    

    and you can access

    $result['User_name'] 
    $result['mark_name'] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get an array that contains information from three tables. The result
I'm trying to get from an Android Uri to a byte array. I have
I am trying to programatically create a bitmap from an array that contains color
I'm trying to get one object from this array and print all of its
I'm trying to get a table form a numpy array at the barplot bottom
I'm trying to get the values from a pointer to a float array, but
I'm trying to get a specific value from a mysql_fletch_assoc array. I explain. Here
I am trying to pass a string that already contains quotation marks from one
So, I have results to send by phpmail stored in arrays and I'm trying
I am trying to remove elements from an array if a value in that

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.