SQL query help for PHP message board
Posted 20 December 2005 - 04:37 PM
I've created a message board for my website. I am trying to display next to the list of post titles the number of reviews that have been posted for that particular post title.
The query below selects all the post titles for a user selected category:
SELECT DISTINCT post_title FROM tablename
WHERE post_category = $user_selected_post_category
What I want to do next is within a for loop display the post_titles from the above query and next to the post_titles put the number of replies. In my database, each reply as a unique id called post_id. What I think is to COUNT all the post_ids for that post_title. The below query shows this:
SELECT COUNT(post_ids) AS no_of_posts FROM tablename
WHERE post_title = $post_title_from_above query.
How can I combine these 2 queries on one page to display '$post_title' and '$no_of_posts' within one for loop also on the same page.
The message board can be found at [a href=\"http://www.mediacritic.co.uk/messageboard2.php?post_category=Films\" target=\"_blank\"]http://www.mediacritic.co.uk/messageboard2..._category=Films[/a]
Posted 21 December 2005 - 05:56 AM
or [php] * 1000... PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...
Posted 23 December 2005 - 10:07 PM
SELECT post_title, ( SELECT COUNT(post_ids) FROM tablename WHERE post_title = t1.post_title ) AS no_of_posts FROM tablename WHERE post_category = $user_selected_post_category GROUP BY post_title
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users