Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Like/Dislike button on posts

Featured Replies

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

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

  • 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

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.