Your DB design isn’t right. I made some changes and added foreign keys. Your data is incomplete and what you want to see is not clear so I couldn’t do a query.
Possible view options
- All posts by a certain user
- All comments to a certain post…
3…
[code]SET FOREIGN_KEY_CHECKS=0;
– Table structure for bans
DROP TABLE IF EXISTS bans
;
CREATE TABLE bans
(
ban_id
int(11) NOT NULL AUTO_INCREMENT,
user_id
int(11) NOT NULL,
ip
text NOT NULL,
PRIMARY KEY (ban_id
),
KEY user_id
(user_id
),
CONSTRAINT bans_ibfk_1
FOREIGN KEY (user_id
) REFERENCES users
(user_id
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
– Records of bans
– Table structure for comments
DROP TABLE IF EXISTS comments
;
CREATE TABLE comments
(
comment_id
int(11) NOT NULL AUTO_INCREMENT,
post_id
int(11) NOT NULL,
user_id
int(11) NOT NULL,
text
text NOT NULL,
ip
text NOT NULL,
date
text NOT NULL,
PRIMARY KEY (comment_id
),
KEY post_id
(post_id
),
KEY user_id
(user_id
),
CONSTRAINT comments_ibfk_1
FOREIGN KEY (post_id
) REFERENCES posts
(post_id
),
CONSTRAINT comments_ibfk_2
FOREIGN KEY (user_id
) REFERENCES users
(user_id
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
– Records of comments
– Table structure for likes
DROP TABLE IF EXISTS likes
;
CREATE TABLE likes
(
like_id
int(11) NOT NULL AUTO_INCREMENT,
post_id
int(11) NOT NULL,
user_id
int(11) NOT NULL,
PRIMARY KEY (like_id
),
KEY post_id
(post_id
),
KEY user_id
(user_id
),
CONSTRAINT likes_ibfk_1
FOREIGN KEY (post_id
) REFERENCES posts
(post_id
),
CONSTRAINT likes_ibfk_2
FOREIGN KEY (user_id
) REFERENCES users
(user_id
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
– Records of likes
– Table structure for posts
DROP TABLE IF EXISTS posts
;
CREATE TABLE posts
(
post_id
int(11) NOT NULL AUTO_INCREMENT,
user_id
int(11) NOT NULL,
title
text NOT NULL,
text
text NOT NULL,
main_text
text NOT NULL,
views
text NOT NULL,
ip
text NOT NULL,
date
text NOT NULL,
PRIMARY KEY (post_id
),
KEY id
(post_id
),
KEY user_id
(user_id
),
CONSTRAINT posts_ibfk_1
FOREIGN KEY (user_id
) REFERENCES users
(user_id
)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
– Records of posts
INSERT INTO posts
VALUES (‘1’, ‘1’, ‘aaaaaa’, ‘aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa’, ‘aaaaaaaaaaaaaaaassad\r\nas\r\ndasd\r\nasd\r\nas\r\ndsa\r\ndsadasd’, ‘13’, ‘::1’, ‘11.30.2016 16:46:32’);
INSERT INTO posts
VALUES (‘3’, ‘1’, ‘sdasdasdjkj’, ‘kjk’, ‘jk’, ‘6’, ‘::1’, ‘11.30.2016 16:52:10’);
– Table structure for users
DROP TABLE IF EXISTS users
;
CREATE TABLE users
(
user_id
int(11) NOT NULL AUTO_INCREMENT,
img
text NOT NULL,
username
text NOT NULL,
email
text NOT NULL,
password
text NOT NULL,
ip
text NOT NULL,
date
text NOT NULL,
PRIMARY KEY (user_id
)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
– Records of users
INSERT INTO users
VALUES (‘1’, ‘http://localhost/GrabPoints/img/avatar.jpg’, ‘admin’, ‘[email protected]’, ‘admin’, ‘::1’, ‘11.29.2016’);
SET FOREIGN_KEY_CHECKS=1;
[/code]