I have this comment table where users can post comment as well as guest, i can fetch users comments like this
SELECT `comments`.`user_id`, `comments`.`pubdate`, `comments`.`comment`,
`comments`.`guest_name`,
`comments`.`id`,
`users`.`username`,
FROM (`comments`)
JOIN `users` ON `comments`.`user_id` = `users`.`user_id`
WHERE `item_id` = '64' AND `section` = 'blog'
problem is guest users don’t have user id hence thier id goes to db as 0 so it is not displayed, how can i show comments of both users and guest ?
You should use
LEFT JOINIf there’s no matching
userforcomments.user_id, thenusers.usernamewill be NULL.