Another post in facebook style tutorials series at 99Points.info. You have seen Facebook like/unlike button if you want to like a post you simple click on “Like” button. Also, you have seen collapsed comments there and when you click on show all comments button it shows all comments. I created this thing and I tried to create same style as it is on Facebook. Please share this if you like and don’t forget to subscribe by email.
Note: No spams and newsletters for subscribers. Thanks !
Database Structure
I used 4 tables for this tutorial, one for saving posts, other for saving comments against that post, one for saving likes of posts and last one is to store IP addresses of users. I used IP to save user likes but when you will use it you should use user ID instead of IP so that you can accurately identify that current user already liked or not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
CREATE TABLE IF NOT EXISTS `facebook_collapsed_posts` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `f_name` varchar(50) NOT NULL, `post` varchar(255) NOT NULL, `f_image` varchar(50) NOT NULL, `date_created` int(11) NOT NULL, `userip` varchar(200) NOT NULL, PRIMARY KEY (`p_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `facebook_collapsed_posts` -- INSERT INTO `facebook_collapsed_posts` (`p_id`, `f_name`, `post`, `f_image`, `date_created`, `userip`) VALUES (2, 'Zeeshan Rasool', 'Facebook style collapsed comments using jQuery, php and mysql.', 'zee.jpg', 1285405523, ''); |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
CREATE TABLE IF NOT EXISTS `facebook_collapsed_likes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `likes` int(11) NOT NULL, `post_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `facebook_collapsed_likes` -- INSERT INTO `facebook_collapsed_likes` (`id`, `likes`, `post_id`) VALUES (1, 0, 2); |
1 2 3 4 |
CREATE TABLE IF NOT EXISTS `facebook_collapsed_ip` ( `userip` varchar(100) NOT NULL, `post_id` int(11) NOT NULL ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
CREATE TABLE IF NOT EXISTS `facebook_collapsed_comments` ( `c_id` int(11) NOT NULL AUTO_INCREMENT, `userip` varchar(200) NOT NULL, `comments` text NOT NULL, `date_created` int(11) NOT NULL, `post_id` int(11) NOT NULL, PRIMARY KEY (`c_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; -- -- Dumping data for table `facebook_collapsed_comments` -- INSERT INTO `facebook_collapsed_comments` (`c_id`, `userip`, `comments`, `date_created`, `post_id`) VALUES (1, '', 'Facebook Like URL data Extract Using jQuery PHP and Ajax http://bit.ly/bYp6qn', 1285424171, 2), (2, '', 'Facebook Style Wall Posting and Comments System using jQuery PHP and Ajax. http://bit.ly/df9t1L', 1285417630, 2), (3, '', 'Facebook Like URL data Extract Using jQuery PHP and Ajax http://bit.ly/bYp6qn', 1285405523, 2), (4, '', 'Facebook Style Wall Posting and Comments System using jQuery PHP and Ajax. http://bit.ly/df9t1L', 1285417630, 2), (5, '', 'Facebook Style Event Creator With jQuery and Ajax. http://bit.ly/b4pIqc', 1285405523, 2), (6, '', 'Facebook Style Wall Posting and Comments System using jQuery PHP and Ajax. http://bit.ly/df9t1L', 1285424171, 2), (7, '', 'Facebook Style Profile Edit script using jQuery, Ajax and PHP. http://bit.ly/bxREzE', 1285405523, 2), (8, '', 'Facebook Style Profile Edit script using jQuery, Ajax and PHP. http://bit.ly/bxREzE', 1285424171, 2), (9, '', 'Facebook Like URL data Extract Using jQuery PHP and Ajax http://bit.ly/bYp6qn', 1285417630, 2), (10, '', 'Facebook Style Suggest a Friend Box Using jQuery and PHP. http://bit.ly/a5Y0pA', 1285417630, 2); |
JQuery Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
$(document).ready(function(){ $('.ViewComments').livequery("click",function(e){ var parent = $(this).parent(); var getID = parent.attr('id').replace('collapsed-',''); var total_comments = $("#totals-"+getID).val(); $("#loader-"+getID).html('<img src="loader.gif" alt="">'); $.post("view_comments.php?postId="+getID+"&totals="+total_comments, { }, function(response){ $('#CommentPosted'+getID).prepend($(response).fadeIn('slow')); $('#collapsed-'+getID).hide(); }); }); /// like $('.LikeThis').livequery("click",function(e){ var getID = $(this).attr('id').replace('post_id',''); $("#like-loader-"+getID).html('<img src="loader.gif" alt="">'); $.post("like.php?postId="+getID, { }, function(response){ $('#like-stats-'+getID).html(response); $('#like-panel-'+getID).html('<a id="post_id'+getID+'" class="Unlike"></a>Unlike'); $("#like-loader-"+getID).html(''); }); }); /// unlike $('.Unlike').livequery("click",function(e){ var getID = $(this).attr('id').replace('post_id',''); $("#like-loader-"+getID).html('<img src="loader.gif" alt="">'); $.post("unlike.php?postId="+getID, { }, function(response){ $('#like-stats-'+getID).html(response); $('#like-panel-'+getID).html('<a id="post_id'+getID+'" class="LikeThis"></a>Like'); $("#like-loader-"+getID).html(''); }); }); }); |
Download all the files and use this stylish tutorial. Thanks !
Comments are closed.