nakins
04-16-2004, 06:07 AM
Hello,
I'm trying to make a php script that uses a free php forum for content management. I have made a script to select the newest topics that are posted to certain forums. For example, say I have a category Sports and a forum called Football. And say I have a post (each) for the superbowl, the rose bowl and the orange bowl and the are replies to each of those topics. I want to select the originating post for the superbowl rose and orange, since the are the first posts for each topic.
I have tried:
"SELECT topic_id FROM posts WHERE forum_id = '$ke' ORDER BY post_time DESC ";
In this case, $ke would be Football. But this doesn't work like I wanted. As it selects the first unique topic_id it comes to and once it has a group of unique topic-id's, orders them by post_time. I think this problems come from an reply entry being made into the table before the original entry. This happens, I think, from posts being deleted and leaving an open spot in the table.
So, I would like to select not only a unique topic_id, but the earlist topic_id.
I've tried: SELECT topic_id, min(post_time)....but that just gives me one id total for each category. I've tried "SELECT topic_id FROM posts WHERE forum_id = '$ke' AND post_time = min(post_time) ORDER BY post_time DESC "; but this gives me an error (invalid use of group by).
Can anyone help me out here?
Thanks
I'm trying to make a php script that uses a free php forum for content management. I have made a script to select the newest topics that are posted to certain forums. For example, say I have a category Sports and a forum called Football. And say I have a post (each) for the superbowl, the rose bowl and the orange bowl and the are replies to each of those topics. I want to select the originating post for the superbowl rose and orange, since the are the first posts for each topic.
I have tried:
"SELECT topic_id FROM posts WHERE forum_id = '$ke' ORDER BY post_time DESC ";
In this case, $ke would be Football. But this doesn't work like I wanted. As it selects the first unique topic_id it comes to and once it has a group of unique topic-id's, orders them by post_time. I think this problems come from an reply entry being made into the table before the original entry. This happens, I think, from posts being deleted and leaving an open spot in the table.
So, I would like to select not only a unique topic_id, but the earlist topic_id.
I've tried: SELECT topic_id, min(post_time)....but that just gives me one id total for each category. I've tried "SELECT topic_id FROM posts WHERE forum_id = '$ke' AND post_time = min(post_time) ORDER BY post_time DESC "; but this gives me an error (invalid use of group by).
Can anyone help me out here?
Thanks