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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:25:18+00:00 2026-06-11T10:25:18+00:00

I have this code: $result = mysql_query(SELECT f_type.`id` AS type_id, f_type.`name` AS type_name, f_thread.`id`

  • 0

I have this code:

$result = mysql_query("SELECT 
f_type.`id` AS type_id,
f_type.`name` AS type_name,
f_thread.`id` AS thread_id,
f_thread.`uid`,
f_thread.`title` AS thread_title,
f_thread.`hits`,
u.`username`

FROM `forum_type` AS f_type
LEFT JOIN `forum_thread` AS f_thread
ON f_type.`id` = f_thread.`type_id` 
LEFT JOIN `users` AS u
ON u.`id` = f_thread.`uid` 
LEFT JOIN `forum_posts` AS f_posts
ON f_posts.`type_id` = f_thread.`id`    

WHERE f_type.`id` = '".$_GET['type_id']."'
ORDER BY f_posts.`date` DESC
") or die (mysql_error());  

It’s about a forum and I want the threads to be sorted like checking which post is the newest in this forum.

I use forum_type (f_type) as a sub-category of forum, which is the top-category. So it’s hierarchy is like this list:

  1. forum
  2. forum_type
  3. forum_thread
  4. forum_posts

And like in the query I’ve written in the code, I wanted to order by the newest post date… but it doesn’t order by that. I don’t know actually what it’s ordered by… can’t see a scheme. I guess this problem’s caused, because of these multiple joins, but I’m not sure.

I would appreciate any suggestions!

  • 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-11T10:25:20+00:00Added an answer on June 11, 2026 at 10:25 am

    Well, you might want to group by threads and select the maximum post date for each thread if you want to list threads.

    SELECT 
    f_thread.`id` AS thread_id,
    f_thread.`uid`,
    f_thread.`title` AS thread_title,
    f_thread.`hits`,
    u.`username`,
    max(f_posts.date) as last_post_date
    
    FROM `forum_thread` AS f_thread
    LEFT JOIN `users` AS u
    ON u.`id` = f_thread.`uid` 
    LEFT JOIN `forum_posts` AS f_posts
    ON f_posts.`type_id` = f_thread.`id`    
    
    WHERE f_thread.type_id = ".$_GET['type_id']."
    
    GROUP BY thread_id
    ORDER BY last_post_date DESC
    

    Hope that helps. f_posts.type_id is a bit suspect, maybe there’s a thread_id instead in the table?

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

Sidebar

Related Questions

I have this code: $result = mysql_query(SELECT * FROM quote ORDER BY RAND() LIMIT
I have this query: $result = mysql_query(SELECT id,pic0,bio,url FROM .$table. WHERE id LIKE '%custom%'
Say I have this code in PHP : $query = mysql_query(SELECT ...); the statement
I have this code: import re def doReplace(toReplace): i = 1 def chapterReplacer(_): result
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>
Hey there, why does this code not work? $qry = mysql_query(SELECT performerid,pic0 FROM .$table.
I have the following code: (query added) $weight_table = mysql_query (SELECT * FROM .$prefix.weight
I have tried this code: <?php $sql=SELECT id, comment FROM comments ORDER BY comments.id
I have this elementary query: SELECT d.description, o.code FROM order_positions AS o LEFT JOIN
i have this code $md_query = SELECT * FROM table ORDER BY id ASC;

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.