joins

hello…
I really need help with that joins all this time i have tried to learn it
my code

SELECT * FROM likes
FULL OUTER JOIN dlikes
ON likes.id = dlikes.id

i need it select from likes and dlikes where id= same for both i just dont know how to do it i really tried learn it but i still can’t get it

You are missing a WHERE clause.

like this?
[php]
$id = $_SESSION[‘id’];
$glikes = mysqli_query($conn,“SELECT * FROM likes
FULL OUTER JOIN dlikes
ON likes.id = dlikes.id
WHERE post_author_id=$id”);
$likes = mysqli_num_rows($glikes);
[/php]
ERROR
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in on line 215
[php]215: $likes = mysqli_num_rows($glikes);[/php]

USE PREPARED STATEMENTS!!!

Your query is failing. If you catch the exception being thrown, you would have a better idea of what was happening.

[php]$gcomments = mysqli_query($conn,“SELECT * FROM comments
INNER JOIN dcomments
ON comments.c_p_author=dcomments.c_p_author”);
$comments = mysqli_num_rows($gcomments);[/php]
it shows me 8 but if i count comments + dcomments it is 6 why it is showing 8?

i just need it shows me how much is in comments where id=1 and how much is in dcomments where id=1 and then count them

Run the query against the database directly. As in PHPmyAdmin, or Workbench, or whatever you are using to design the tables.

If you only want counts, just do a COUNT(*) rather than query and grab the number.

Sponsor our Newsletter | Privacy Policy | Terms of Service