June 28, 201115 yr Hey Ive got a post/message board system in place. I would to add a "Like" and "dislike" function to each post. How can this be done? Is it .PHP , HTML or JAVASCRIPT Please aid me on how this can be done
June 28, 201115 yr How can this be done? Is it .PHP , HTML or JAVASCRIPT all of them the simplest way is to create a script like vote.php and pass some parameters to that script: like: vote.php?post_id=123&vote=1 dislike: vote.php?post_id=123&vote=0 where 123 is a post id in the database in script you need to check if a user has already voted (cookie or database) it can return the html code with the updated counter, etc.. and to make thing cooler you can use ajax, for example jquery .get method to call that voting script and get the result
June 28, 201115 yr Author all of them the simplest way is to create a script like vote.php and pass some parameters to that script: like: vote.php?post_id=123&vote=1 dislike: vote.php?post_id=123&vote=0 where 123 is a post id in the database in script you need to check if a user has already voted (cookie or database) it can return the html code with the updated counter, etc.. and to make thing cooler you can use ajax, for example jquery .get method to call that voting script and get the result Right i kind of understand. so for the post_id i should use $_GET to get the id from the database for the message/post? Ive never used jquery yet i believe so i will read into it! Do you know any good tutorials i could follow? Ive googled so much but i just keep getting stupid facebook things
June 28, 201115 yr Right i kind of understand. so for the post_id i should use $_GET to get the id from the database for the message/post? yup, // vote up: $postId = (int) (isset($_GET['post_id']) ? $_GET['id'] : 0); UPDATE post SET num_votes = num_votes + 1 WHERE id = $postId; Ive never used jquery yet i believe so i will read into it! You definitely should do that Do you know any good tutorials i could follow? Ive googled so much but i just keep getting stupid facebook things i think the best source of knowledge is the official documentation page, it has a lot of simple examples, in your case you may try this: <a id="like" href="javascript:void(0)">[like]</a> <a id="dislike" href="javascript:void(0)">[dislike]</a> $('#like').click(function(){ $.get('vote.php?post_id=123&vote=1', function(html){ alert(html); }); }); $('#dislike').click(function(){ $.get('vote.php?post_id=123&vote=0', function(html){ alert(html); }); });
Create an account or sign in to comment