how can i get all post for me and for user who i follow him
i have 3 table.
1st is for user info. 2nd is for post where user insert to it and relation
with user table by user_id. 3rd is for user who i follow him and relation
with user table by user_id.
now in home page i need to show all posts where i insert on it and where
user i follow him insert into table post.
i will try to make this MySQL by :-
SELECT * FROM users ,
(SELECT * FROM events where ev_user_id in
(
( select * from follow where follow.fo_user_id = '".$user_id."' )
, '".$user_id."'
)
) as post
where post.ev_user_id = users.id
order by post.ev_date DESC limit $to , $from
where $user_id is id for user.
here i get error that:-
Operand should contain 1 column(s)
if i follow one user its work, but when i follow more than one user, its
display above error.
how can i get all post for me and for user who i follow him
==================================== events table is the table for post
CREATE TABLE `events` (
`ev_id` int(11) NOT NULL auto_increment,
`ev_user_id` int(11) NOT NULL,
`ev_type` varchar(222) NOT NULL,
`ev_text` text NOT NULL,
`ev_pic` varchar(222) NOT NULL,
`ev_date` varchar(22) NOT NULL,
PRIMARY KEY (`ev_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=211 ;
table for user which i follow him
CREATE TABLE `follow` (
`fo_id` int(11) NOT NULL auto_increment,
`fo_user_id` int(11) NOT NULL,
`fo_user_id_follow` int(11) NOT NULL,
`fo_date` varchar(22) NOT NULL,
PRIMARY KEY (`fo_id`),
UNIQUE KEY `fo_user_id` (`fo_user_id`,`fo_user_id_follow`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
table for user info
CREATE TABLE `users` (
`id` bigint(20) unsigned NOT NULL auto_increment,
`fullname` varchar(222) NOT NULL,
`username` varchar(60) NOT NULL,
`password` varchar(64) NOT NULL,
`email` varchar(50) NOT NULL,
`address` varchar(300) NOT NULL,
`phone` varchar(20) NOT NULL,
`skype` varchar(20) NOT NULL,
`facebook` varchar(40) NOT NULL,
`msn` varchar(90) NOT NULL,
`mobile` varchar(20) NOT NULL,
`more` text NOT NULL,
`time` varchar(50) NOT NULL,
`lastlogin` varchar(50) NOT NULL,
`role_id` tinyint(1) NOT NULL default '2',
`code` varchar(7) NOT NULL,
`active` tinyint(4) NOT NULL default '3',
`wieght` int(11) NOT NULL,
`tall` int(11) NOT NULL,
`birthdate` varchar(20) NOT NULL,
`gender` varchar(5) NOT NULL,
`fat` int(11) NOT NULL,
`fittnes` int(11) NOT NULL,
`status` int(11) NOT NULL,
`pic` varchar(222) NOT NULL,
`regdate` varchar(22) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=396 ;
No comments:
Post a Comment