Ok, so I have 3 tables:
of users
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL, `user_username` varchar(25) NOT NULL, `user_email` varchar(100) NOT NULL, `user_password` varchar(255) NOT NULL, `user_enabled` int(1) NOT NULL DEFAULT '1', `user_staff` varchar(15) NOT NULL DEFAULT '', `user_account_type` varchar(20) NOT NULL DEFAULT '0', `user_registerdate` date NOT NULL, `user_twofactor` int(11) NOT NULL DEFAULT '0', `user_twofackey` varchar(255) NOT NULL, `user_forgot_email_code` varchar(255) NOT NULL, `user_emailverified` varchar(25) NOT NULL DEFAULT 'unverified', `user_banned` varchar(25) NOT NULL DEFAULT 'unbanned', `user_has_avatar` int(11) NOT NULL DEFAULT '0', `user_has_banner` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1;
the company
CREATE TABLE IF NOT EXISTS `company` ( `company_id` int(11) NOT NULL, `company_name` varchar(100) NOT NULL, `company_user` int(11) NOT NULL, `company_enabled` varchar(50) NOT NULL DEFAULT 'enabled', `company_has_avatar` int(5) NOT NULL DEFAULT '0', `company_has_banner` int(5) NOT NULL DEFAULT '0' ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
training_company
CREATE TABLE IF NOT EXISTS `training_company` ( `training_company_id` int(11) NOT NULL, `training_company_name` varchar(100) NOT NULL, `training_company_user` int(11) NOT NULL, `training_company_enabled` varchar(50) NOT NULL DEFAULT 'enabled', `training_company_has_avatar` int(5) NOT NULL DEFAULT '0', `training_company_has_banner` int(5) NOT NULL DEFAULT '0' ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
Each has a profile that has an incremental identifier, so it will have the same identifier, I just define them through the type, so the user will be a user, training will be trained, and the company will be a company, I allow the user to do one of them.
SQL
SELECT * FROM timeline_status LEFT JOIN users ON timeline_status.timeline_status_user = users.user_id LEFT JOIN timeline_likes ON timeline_status.timeline_status_id = timeline_likes.timeline_likes_main_status LEFT JOIN friends ON timeline_status.timeline_status_user = friends.friends_friend LEFT JOIN user_personal_information ON timeline_status.timeline_status_user = user_personal_information.user_personal_information_user LEFT JOIN following ON timeline_status.timeline_status_user = following.following WHERE timeline_status_enabled = 'enabled' AND timeline_status.timeline_status_type = 'user' AND (timeline_status.timeline_status_user = :status_user OR friends.friends_user = :friend_user) AND (timeline_status_privacy = 'onlyme' AND timeline_status_user = :status_user2 OR timeline_status_privacy = 'public' OR timeline_status_privacy = 'private') GROUP BY timeline_status_id ORDER BY timeline_status_date DESC LIMIT :start, :end
Thus, I would like to select users if type = user, and the string exists in followers and / or friends, choose from companies or undergo training from followers if type = company or training.
My status has a company / user / training ID and type, so I know which table the "user from" selects
my next table;
CREATE TABLE IF NOT EXISTS `following` ( `following_id` int(11) NOT NULL, `following_user` int(11) NOT NULL, `following_type` varchar(50) NOT NULL, `following` int(11) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
timeline status:
CREATE TABLE IF NOT EXISTS `timeline_status` ( `timeline_status_id` int(11) NOT NULL, `timeline_status_user` int(11) NOT NULL, `timeline_status_privacy` varchar(25) NOT NULL DEFAULT 'public', `timeline_status_type` varchar(25) NOT NULL DEFAULT 'user', `timeline_status_post` text NOT NULL, `timeline_status_date` datetime NOT NULL, `timeline_status_enabled` varchar(25) NOT NULL DEFAULT 'enabled' ) ENGINE=InnoDB AUTO_INCREMENT=123 DEFAULT CHARSET=latin1; -- -- Dumping data for table `timeline_status` -- INSERT INTO `timeline_status` (`timeline_status_id`, `timeline_status_user`, `timeline_status_privacy`, `timeline_status_type`, `timeline_status_post`, `timeline_status_date`, `timeline_status_enabled`) VALUES (98, 3, 'private', 'user', 'hello', '2015-10-02 16:29:48', 'enabled'), (99, 3, 'onlyme', 'user', 'yo', '2015-10-02 16:29:56', 'enabled'), (100, 3, 'public', 'user', 'fghyjt', '2015-10-02 17:51:28', 'enabled'), (101, 1, 'private', 'training', 'teest..', '2015-10-03 14:26:45', 'enabled'), (102, 15, 'public', 'company', 'hello', '2015-10-06 13:32:30', 'enabled');
So, how can I do this if the next type = company chooses a company, if after tye = training I choose from training, and if the next type = user, save sql as it is at the moment. Since at the moment I am following the company with identifier 1, but there is a user with identifier 1, so I get their statuses.