Jump to content

Can't combine 2 queries


V

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

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.