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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:42:32+00:00 2026-05-27T09:42:32+00:00

I have a forum and im looping through the replies to a thread, and

  • 0

I have a forum and im looping through the replies to a thread, and for each instance its querying the members database for the users info.

I’d like to do it in one query if possible. What kind of sql join do I need for this?
Here’s my existing code:

$sql_result = mysql_query("SELECT * FROM forum_replies WHERE topic='$topic_id' AND del=0 ORDER BY date asc", $db); 
while($rs = mysql_fetch_array($sql_result))
{
   $sql_result2 = mysql_query("SELECT * FROM members WHERE id='$rs[author]'", $db);
   $rs2 = mysql_fetch_array($sql_result2);

Queries:

SELECT * FROM forum_replies WHERE topic='$topic_id' AND del=0 ORDER BY date asc
SELECT * FROM mobsters WHERE id='$rs[author]'"
  • 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-27T09:42:33+00:00Added an answer on May 27, 2026 at 9:42 am

    I guess you are looking for something like this:

    select * 
        from forum_replies as fr
        left join mobsters as m on m.id = fr.author
        where
            fr.topic = :topic_id
            and del = 0
        order by fr.date asc
    

    You want to select the replies and the data of the author alongside with every row. :topic_id is the place for your topic ID (a notation used in PDO which you should look up and use instead of the mysql_ functions).

    I have an important suggestion though: instead of select *, you should specify what you really want to return from your tables, what you really need.

    For example:

    select fr.id, fr.title, fr.date, m.id, m.nickname
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model which has a collection of users. I'm looping through this
I have a discussion forum/blog engine working with web forms. Each post contains html
Having trouble looping through multiple rows in a SQL table and getting the info
I am generating the html form by looping through the form variables like below
So I have a forum application and double nested resources. Section-->Topic-->Replies and are set
I have a html table that is generated by looping through DB entries. On
I am looping through a bunch of array type fields. I have two checkboxes
I have been looking at a couple html/css form frameworks like Uni-Form and Formy
I have a forum on a website I master, which gets a daily dose
Using PHP and MySQL, I have a forum system I'm trying to build. What

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.