Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:10:06+00:00 2026-05-23T23:10:06+00:00

I am developing a comments moderating system as part of my website so i

  • 0

I am developing a comments moderating system as part of my website so i can see a list of comments before they are published so i can either publish them as okay or delete them if inappropiate.

I have haof of my SQL working ok where i can see who the author of the comment is, the date posted, the comment etc and even what page it was on (whether it was a news page, blogs or events page).

What i can’t get it to do however is display the title of the page (news title, blog title or event title).

This would really help so i would like it incorporated into my query.

How my query works now is that it select everything in the comments table including the physical page (news, blogs, events).

What i imagine it to do is once it knows what page the comment belongs to, is query that table and get the title.

Has anyone any idea how i do this? Do i need a nested select once the page has been chosen?

Here is my current query (the $get_id) gets the comment id from the url)

   SELECT c . * , ifnull( cc.commentcount, 0 ) AS ccount
        FROM comments c
        LEFT OUTER
        JOIN (

        SELECT page, pageid, count( * ) AS commentcount
        FROM comments
        GROUP BY page
        ) AS cc ON cc.pageid = c.pageid
        WHERE c.commentid = '$get_id'

and here is database structure if it helps

CREATE TABLE `comments` (
  `commentid` int(5) NOT NULL auto_increment,
  `page` varchar(20) NOT NULL default '',
  `pageid` int(3) NOT NULL default '0',
  `user` varchar(40) NOT NULL default '',
  `email` varchar(100) NOT NULL default '',
  `website` varchar(100) NOT NULL default '',
  `comment` text NOT NULL,
  `posted` datetime NOT NULL default '0000-00-00 00:00:00',
  `status` enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (`commentid`)
)

// the tables for news, blogs and events are pretty much the same
CREATE TABLE `news` (
  `id` int(4) NOT NULL auto_increment,
  `title` varchar(100) NOT NULL default '',
  `content` text NOT NULL,
  `postdate` date NOT NULL default '0000-00-00',
  `photo` varchar(50) NOT NULL default '',
  `alternate` varchar(50) NOT NULL default '',
  `archived` char(1) NOT NULL default 'n',
  `page` varchar(4) NOT NULL default 'news',
  PRIMARY KEY  (`id`)
)

I don’t know if this helps but this is how i display the comments once published

SELECT  c.*, 
    b.title,  
    ifnull(cc.commentcount,0) as ccount 
        FROM comments c 
    INNER 
        JOIN blogs b
            ON c.pageid = b.id 
    LEFT OUTER
        JOIN (SELECT page,pageid, 
                     count(*) as commentcount 
                FROM comments 
                GROUP BY page) as cc 

            on cc.pageid = c.pageid
    WHERE c.pageid='$blogid'

EDIT: Current query with proposed changes from Ain

SELECT c. * , ifnull( cc.commentcount, 0 ) AS ccount,
CASE c.page
WHEN 'news'
THEN SELECT title
FROM news
WHERE id = c.pageid
WHEN 'blog'
THEN SELECT title
FROM blog
WHERE id = c.pageid
ELSE ''
END FROM comments c
LEFT OUTER JOIN (

SELECT page, pageid, count( * ) AS commentcount
FROM comments
GROUP BY page
) AS cc ON cc.pageid = c.pageid
WHERE c.commentid = '2'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:10:07+00:00Added an answer on May 23, 2026 at 11:10 pm

    Assuming that field page in table comments contains values like “news”, “blog” etc to mark the “page type” comment belongs to and comments.pageid is FK to appropriate table, you could do something like

    CASE c.page
      WHEN 'news' THEN SELECT title FROM news WHERE id = c.pageid
      WHEN 'blog' THEN SELECT title FROM blog WHERE id = c.pageid
      ELSE ''
      END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a web application that can support threaded comments. I need the
Developing a .NET WinForms application: how can I check if the window is in
Developing a website and just trying to get back into the swing of (clever)
I am developing a comments box that will save the comment through a JQuery
Seems like max table comments length in mysql is only 60 characters. I'm developing
I'm developing an blog using ASP.NET , and I want that the user can
I am developing an app on iphone that lets user take photos, add comments
I am developing with Eclipse + PDT. I've been adding phpdoc comments into my
I am developing a flash application for a website I have no direct access
We are developing a system for Android devices. For that we are using FC16,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.