Facebook Wall Script 1.0 | Lessoncup Programming Blog

Saturday, 23 November 2013

Facebook Wall Script 1.0

Few days back i have posted one lesson Facebook Wall Script with the features of entering posts, giving comments to the posts and delete the posts and comments, now i have updated with displaying old posts with that you can see the old updates along with new posts.



Required Files

  • index.php // is main file and all the JS and Css scripts will store here
  • loadposts.php // used to displaying old posts
  • posts.php // used to adding posts
  • comment.php // used to adding comments
  • comdelete.php // used to delete the comments
  • delete.php // used to delete the posts

Script Files

<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="wall.js"></script>

i am not giving overall info here just check my previous lesson  Facebook Wall Script to get other files info, just i am giving how to display the old messages in index.php file, 

inside the UL tag just include the loadposts.php file
<div id="wallBoard">
<div id="statusbox">
<form action="" method="post" name="statusform">
<textarea name="status" class="status" id="status" placeholder="What's on your mind?" title="What's on your mind?"></textarea>
<div id="postbar" class="postbar">
<input name="post" type="submit" value="Post"  class="postbtn" />
</div>
</form>
</div>

<div id="loader"></div>
<div class="comment_box">
<ul id="updatepost">

<?php

include "loadposts.php";

?>

</ul>
</div>
</div>

loadposts.php

write the query to display the old posts  from posts table and loop the fetched rows into li tag and write the query inside the loop to display the comments related to the posts which have already given
<?php
extract($_REQUEST);
include("db.php");

$sql=mysql_query("select * from posts order by pid desc");
while($full=mysql_fetch_array($sql)){

$pid=$full['pid'];
$pname=$full['post'];

?>
<li id="post<?php echo $pid;?>">

<img src="pik.jpg" align="absmiddle" style="float:left; width:50px; border:solid #CCC1px; padding-right:5px;">
<h1 style=" font-size:12px; margin-top:0; "><?php echo $pname;?></h1>
<div class="delete" id="<?php echo $pid;?>">
X
</div>
<a class="addComment" id="<?php echo $pid?>">Comment</a>
<div id="loadcomment<?php echo $pid;?>">

<?php
$comsql=mysql_query("select * from comments where pid=$pid order by cmid");
$countcom=mysql_num_rows($comsql);
while($full=mysql_fetch_array($comsql)){
$cmid=$full['cmid'];
$cname=$full['comment'];
?>

<div id="comdisplay<?php echo $cmid;?>" class="comdisplay">
<div class="comdelete" id="<?php echo $cmid;?>">
X
</div>
<?php echo $cname;?>
</div>

<?php }?>

</div>
<div id="commentBox<?php echo $pid?>" class="combox" <?php if($countcom>0){?> style="display:block;" <?php }?>>
<form action="" method="post" name="<?php echo $pid?>">
<textarea name="comment" class="comment" type="text" id="comment<?php echo $pid?>" style="float:left;" placeholder="Write a Comment..">
</textarea>
<input name="comBtn" class="comBtn" id="<?php echo $pid?>" type="submit" value="Comment" />
</form>
</div>
</li>
<?php }?>

Database

Create the database
--
-- Table structure for table `posts`
--

CREATE TABLE IF NOT EXISTS `posts` (
  `pid` int(11) NOT NULL AUTO_INCREMENT,
  `post` varchar(255) NOT NULL,
  PRIMARY KEY (`pid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

--
-- Table structure for table `comments`
--

CREATE TABLE IF NOT EXISTS `comments` (
  `cmid` int(11) NOT NULL AUTO_INCREMENT,
  `pid` int(11) NOT NULL,
  `comment` varchar(255) NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`cmid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

--


Live Demo   Download Script

3 comments :

  1. display only in chrome and comments are not updated

    ReplyDelete
    Replies
    1. i have not connected new entries to database for security reasons and it is working in all browsers

      Delete
  2. hi, i love your site and i'm learning for myself, one thing that i want to learn myself about the wall scripts, is this possible when user entered comment and than list of comment slidedown then show new comment instead of both same time! i'm trying to figure out how that works with slideshow to slidedown list of comment before show new comment in first row!

    ReplyDelete

Mohammad Khasim
Blogger | Web Developer
Hyderabad - INDIA
lessoncup@gmail.com

PHP | My SQL | JQUERY
Web Development Tools | CMS | Frameworks | SEO

Get my Latest Lessons