I have a simple PHP script that allows users to comment on a page. This works fine, but I am having difficulties adding a "like button" to it.
The contents for each comment are stored in a database. Here's the code I used for it just to give you an idea
CREATE TABLE IF NOT EXISTS `comments` (
`id` int(128) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=101675,
`postername` varchar(16) NOT NULL,
`postmessage` varchar(400) NOT NULL,
`posterip` varchar(128) NOT NULL,
`postdate` varchar(128) NOT NULL,
`likes` int(100) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=101675 DEFAULT CHARSET=latin1;
And here is something what my the code for my like button would look like:
<a href='#' class='likecomment' onclick='likecomment();' id='".$id."'>Like</a>
the PHP variable $id matches the value of the ID column in my database. So, for example, let's say we had a row with an ID of 1, then the ID for the like button for the HTML of that comment would also be 1.
My thinking was that if they matched, when people clicked on it I could use javascript to get the ID and then include a PHP file that connects to the database and selects the row that contains that ID in the ID column. I don't need help with connecting to the database, but would appreciate help with the javascript that gets the ID of the like button clicked and then passes it to my PHP script so I can select the proper row to give the like to.
In short, I need it so when they click the like button, it increases the value of the likes column by 1. I know the PHP to do this, but need help with the jquery / javascript. Much appreciated. Here is what I have so far with, although it isn't much.
function likecomment() {
$.get("like.php");
return false;
}