Jump to content

Recommended Posts

I've been struggling to combine 2 queries but I keep getting errors. They are..

 

"SELECT topics.*, categories.* FROM topics, categories WHERE topics.cat_id = categories.cat_id AND topics.views >= 2 ORDER BY topic_date DESC";

 

and

 

"SELECT *, COUNT(post_id) as total_posts FROM posts WHERE topic_id = {$row["topic_id"]} ORDER BY post_date DESC";

 

Is it even possible to combine them? :suicide: Pls help.

Link to comment
https://forums.phpfreaks.com/topic/208105-cant-combine-2-queries/
Share on other sites

grissom, hmm I'm not sure where to add that, I'm trying to figure out how to combine the 2.

 

Mchl,

 

In the first query, the Topics table are like subcategories of the Category table. Each Category as a number of Topics.

 

topics.views >= 2 is the unique views of a topic  (for a "sort by") script I wrote. So I'll also have for example topics.comments >=5 for most commented. Combing the 2 queries would be ideal because I can query just once for each condition. 

 

And the second query tells the total number of posts that are in a topic. So both should echo out

 

Topic Name        .......          Category (it belongs to)          ...........          Total Number of Posts

 

Hope that makes sense

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.