DEVELOPMENT

Here, I've aim to show how a like button works, as you sees in social networking sites.

THE SITUATION




ENTRY.PHP
<!DOCTYPE html>
<html>
<head></head>
<body>
<div align="center" style="font-family:Arial;width:400px;padding:5px;background:#ccc;"><p><b>Enter username of your choice to enter.</b></p>
<form action="index.php" method="post"><input type="text" name="user" />
<input type="submit" value="Enter" />
</form>
</div>
</body>
</html>
    

INDEX.PHP
<?php
session_start();
$_SESSION['user']=$_POST['user'];
if(!isset($_SESSION['user'])){ 
 header("Location:entry.php");
 }
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script> 
?> 
$(document).ready(function(){
 
 $("#tline").load("table.php");
 
 $(document).on("click", "#like", function(){
 var ID=$(this).val();
 $.ajax({

 type: "POST",

 url: "add_like.php",

 data:"q="+ID, 

 cache: false, 

 success: function(data){

 $("#tline").load("table.php");

 } 
 });

 return false;});

 
 $(document).on("click", "#dislike", function(){
 var ID=$(this).val();
 $.ajax({

 type: "POST",

 url: "add_dislike.php",

 data:"q="+ID, 

 cache: false, 

 success: function(data){

 $("#tline").load("table.php");

 } 
 });

 return false;
 });

});
</script>
</head>
<body>
<div id="tline"></div>
</body>
</html>


THE DATABASES

We have to deal with two tables. One(likes) for storing the post's detail and the other one(wlikes) for storing the "user_id" of the user with the "post_id" corresponding to the post liked by him/her.



likes

wlikes


Leave a Comment  
Download Code(53)





All rights reserved, the content is copyrighted to the author.

RELATED POST