Jump to content

[SOLVED] Blog style with posts and replies.. how to do?


Recommended Posts

Hello,

I could use some help writing a statement that I just can not seem to solve.

 

The project I am working is similar to that of a blog.  A user makes a post and then people can reply to that post.  The problem is every time someone makes a reply, it is showing the original post again instead of adding the comment to the original.

 

so here is what I would like it to achieve:

Original Post

- comment 1

- comment 2

- comment 3

 

and instead it is doing this:

Original Post

- comment 1

Original Post

- comment 2

Original Post

- comment 3

 

Here is some more details on what I have going:

 

MySQL Version: 5.0

 

my statement:

 

SELECT p.ID as pID, p.user as pUser, p.comment as pComment, p.datetime as pDateTime, c.ID as cID, c.parentID as cParentID, c.user as cUser, c.comment as cComment, c.datetime as cDateTime, u.username as uUser, u.avatar as uAvatar, u.pavatar as pAvatar, nu.avatar as nuAvatar, nu.pavatar as nupAvatar 
FROM egg_posts p 
LEFT JOIN egg_comments c ON p.ID = c.parentID 
LEFT JOIN egg_users u ON p.user = u.username 
LEFT JOIN egg_users nu ON c.user = nu.username 
ORDER BY c.datetime DESC, p.datetime DESC

 

my tables:

 

CREATE TABLE `egg_comments` (

`ID` int(11) NOT NULL auto_increment,

`parentID` int(11) NOT NULL,

`user` varchar(16) default NULL,

`comment` text NOT NULL,

`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP,

PRIMARY KEY  (`ID`)

) ENGINE=MyISAM AUTO_INCREMENT=23 DEFAULT CHARSET=utf8

 

CREATE TABLE `egg_posts` (

`ID` int(11) NOT NULL auto_increment,

`user` varchar(16) default NULL,

`comment` text NOT NULL,

`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP,

PRIMARY KEY  (`ID`)

) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=utf8

 

 

CREATE TABLE `egg_users` (

`ID` int(11) NOT NULL auto_increment,

`username` varchar(16) NOT NULL,

`pw` varchar(32) NOT NULL,

`name` varchar(150) NOT NULL,

`email` varchar(255) NOT NULL,

`avatar` varchar(255) default NULL,

`pavatar` varchar(6) default NULL,

`gender` char(1) NOT NULL,

`address` varchar(255) default NULL,

`dob` varchar(50) NOT NULL,

`datecreated` timestamp NOT NULL default CURRENT_TIMESTAMP,

`active` tinyint(1) NOT NULL,

PRIMARY KEY  (`ID`),

UNIQUE KEY `username` (`username`),

UNIQUE KEY `email` (`email`)

) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8

 

 

Thanks for any help or suggestions, it is greatly appreciated!

 

 

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.