Database Scheme:
http://pastebin.com/aPXk1rMf
I’m want to select “post owner’s uName” and “comment owner’s uName” from “comments” table (i.e. I think I need cOwnerID>uName and pID>uID>uName) so that I can log some activities right after a comment is posted.
I tried to use MySQL joins in order to achieve that but I couldn’t; so here’s what I tried in vain.
$result = dbquery("INSERT INTO comments VALUES ('','$pID','$ownerID','$cmnt')"); // inserting a comment
$lastID = mysql_insert_id();
$res = dbquery("SELECT
users.username AS username
FROM `comments`
LEFT JOIN `users` on comments.cOwnerID = users.uID
WHERE (cID='$lastID')");
I think you have to use aliases for table users, because, actually, you will have two joins on this table : one for the post author and another for the comment’s author.
Try something like this :