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

  • Home
  • SEARCH
  • 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 8674841
In Process

The Archive Base Latest Questions

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

I had some help in another thread about having an issue with pulling data

  • 0

I had some help in another thread about having an issue with pulling data from 2 tables in MySQL, it appears I needed inner joins.

My Tables:

USERS 
  --id (int)
  --username (varchar)

USER_FOLLOW
  -- id (int)
  -- follower (int)
  -- user (int)
  -- subscribed (current_timestamp)

The Query, $following =

SELECT ufollower.id AS follower_id,
ufollower.username AS follower_name,
ufollowed.id AS user_id,
ufollowed.username AS user_name
FROM
/* JOIN twice against users, once to get the follower and once to get the followed */
user_follow 
/* users aliased as ufollower to get the follower details */
JOIN users ufollower ON ufollower.id = user_follow.follower
/* users aliased as ufollowed to get the followed details */
JOIN users ufollowed ON ufollowed.id = user_follow.user
WHERE
user_follow.user = $p_id

p_id is the profile ID of the person i’m looking at.

I need to show the usernames of who I’m following and who I’ve followed. The code I currently have for some reason is showing me 3 times instead of the 3 people I’m following:

while($apple = mysql_fetch_array($following)){
  echo '<a href="'.$apple['user_name'].'">'.htmlspecialchars($apple['user_name']).'</a> ';
}

Sorry for opening another thread on this, I’ve been staring at it for hours and I can’t get my head around 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-06-12T19:48:14+00:00Added an answer on June 12, 2026 at 7:48 pm

    At a glance it appears that you are displaying the wrong user’s name, showing the followed instead of the follower. Change your PHP code to the following:

    while($apple = mysql_fetch_array($following)){
      echo '<a href="'.$apple['follower_name'].'">'.htmlspecialchars($apple['follower_name']).'</a> ';
    }
    

    Note that your query actually is only returning users that are following you, it does not include users that you are following (which would be those with user_follow.follower = $p_id). Of course, for those users, you actually do want to display the user_name column…

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

Sidebar

Related Questions

I'm having an issue with some asynchronous JavaScript code that fetches values from a
Need some help with this problem in implementing with XSLT, I had already implemented
I had received some really good help earlier, and I appreciate it. I have
In another post , I was wondering if someone had also emails from Google
I'm having trouble with some PHP since yesterday, looked through the web and had
I had some code that constructed an object: function gridObjConst(id, itemName, itemPrice, itemListPrice, width,
we had some demands here in my job that include working with asp. We
I had some issues with XPTemplate vim plugin. Sometimes it yields with errors, and
I had some experience of android but know almost nothing of GCC Makefile. Here
I had some problems with my subversion server and i had to restore it

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.