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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:51:01+00:00 2026-05-25T02:51:01+00:00

i have built small forum script in my index page i am using $query

  • 0

i have built small forum script

in my index page i am using

$query = mysql_query("SELECT * FROM threads");
while($threads = mysql_fetch_array($query)){
    echo 'Thread title ' . $threads['thread_title'];
    echo '<br />Thread content ' . $threads['thread'];
}

to print the full site posts!

Now i want display the post category and post tags under the title

How i can get the categories and tags of post ?

i have table contain this information

table name -> relations

columns

post_id|category_name

i want join this table and get the category_name of each post!

so what is the right query?

NOTE: my site database is big .. so i want the speedy query

thank you very much

  • 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-25T02:51:01+00:00Added an answer on May 25, 2026 at 2:51 am

    You should post the list of tables and fields they contain for the data that you want to see.

    But the general idea should be something like this (assuming threads table has a foreign key on post_id to relations table’s post_id):

    SELECT t.*, r.category_name FROM threads as t
    INNER JOIN relations as r on t.thread_id = r.thread_id
    

    Just updated the above query based on the fields you just listed.

    FYI: if you are concerned about performance, you should do the join of the data in your database query as shown above, executing additional queries for each row in your initial dataset will generate additional calls * number of threads. Now multiple that by the number of users viewing that page and the load on the database grows exponentially, and unnecessarily. All that can be done in one database query so that each user will only trigger one query in the database as opposed to hundreds or thousands potentially per view of the page.

    Ok, in that case try something like this:

    SELECT t.*, GROUP_CONCAT(r.category_name ORDER BY r.category_name SEPARATOR " ") as category_name 
    FROM threads as t
    INNER JOIN relations as r on t.thread_id = r.thread_id
    GROUP BY r.thread_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am quite new to django, and I have built a small page using
I have a small ajax application built with php. Using phpMyAdmin I have set
I have built a web page which contains a Crystal Report built using the
I have built a small app using javascript. I am using javascript for form
i have made an small script to allow users to build they page or
I am a broke college student. I have built a small web app in
I have a small RIA that I built as a learning/make-my-life-easier project that uses
I have built a blog using Ruby on Rails. New to both. I am
With the help of some nice people from SO I have slowly built a
I have a small form which I built mostly in interface builder: When the

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.