Jump to content

Mysql Joining Queries


Andy11548

Recommended Posts

Hello,

 

I could do with some help joining this query in to another query. I'm completely and utterly blagged on what I'm doing now.

 

I need this query:

mysql_query("SELECT * FROM `users` WHERE `username`='".$_SESSION[username]."'");

 

placed into this one:

mysql_query("
	   SELECT
	   f1.cat_name as CatName,
	   f1.cat_id as CatID,
	   f2.cat_id as SubCatID,
	   f2.sub_id as SubID,
	   f2.sub_name as SubName,
	   f2.sub_desc as SubDesc,
	   f3.topic_id as TopicID,
	   f3.user_id as UserTopicID,
	   f3.topic_name as TopicName,
	   f3.topic_message as TopicMessage,
	   f4.user_id as UserReplyID,
	   f5.username as Username,
	   
	   (SELECT COUNT(*) FROM forum_topics as f3 WHERE f3.sub_id = f2.sub_id) as TopicAMT,
	   (SELECT COUNT(*) FROM forum_replies as f4 WHERE f4.topic_id = f3.topic_id) as ReplyAMT
	   
	   FROM `forum_cats` as f1
	   		LEFT JOIN `forum_sub` as f2
	   			ON f1.cat_id = f2.cat_id
	   		LEFT JOIN `forum_topics` as f3
	   			ON f2.sub_id = f3.sub_id
	   		LEFT JOIN `forum_replies` as f4
	   			ON f3.topic_id = f4.topic_id
	   		LEFT JOIN `users` as f5
	   			ON f4.user_id = f5.user_id
	   			
	 WHERE f1.cat_id='$cat' $getSub $getTopic

	 ORDER BY f2.sub_id ASC, f4.reply_id DESC
	 ");

 

Help would be appreciated.

 

Thanks,

Andy.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.