Jump to content

massive query


Julius

Recommended Posts

Hi,

 

I have 5 tables:

 

categories

      id, name

forums

    id, cat_id, name, description

topics

    id, forum_id, name, date, user_id

posts

    id, topic_id, post, date, user_id

users

    id, nick, password

 

im trying to make a forum. on the main page of it, i want to show category name(will be at least 3 categories), forum name and description, latest post in that forum author name and topic name where post was posted. I want to make as less queries as i can. so, can anyone help me with that? I need: name from categories table, name from forums table, name from topics table, latest post user_id from posts table, nick from users table where id=user_id (from posts). can this all be retrieved with one query?

Link to comment
https://forums.phpfreaks.com/topic/252520-massive-query/
Share on other sites

what do you mean? i have heard about 'join', googled for it, found some examples, tried, but they don't do exactly what I want. I dont want you to write the whole query for me, just give me a hint. what i tried:

SELECT categories.name, forums.name, topics.name,
posts.date, users.nick
FROM categories LEFT JOIN (forums, topics, posts, users)
ON (forums.cat_id=categories.id AND topics.fid=forums.id AND posts.tid=topics.id AND users.id=posts.author)

i think this might do the trick after some modifications, am I thinking right? this query takes only one forum (but there are three of them).

Link to comment
https://forums.phpfreaks.com/topic/252520-massive-query/#findComment-1294696
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.