Index.php:
<?php include 'class.php'; $db=new database(); $db->connect(); ?> <link rel="stylesheet" href="wall.css" type="text/css" /> <script type="text/javascript" src="jquery-latest.js"></script> <script> $(document).ready(function() { $('#textpost').click(function() { var b=$("#fbpost").val(); var dataString = 'fbwall='+b; $.ajax( { type:"POST", async: false, url:"ajax.php", data: dataString, success: function(data) { $("#fbpost").val(""); $("#viewpost").html(data); } }); }); }); </script> <div id="container"> <div> <img src="facebook-logo.jpg" width="200" height="75"/> </div> <div id="post"> <form action="" method="post"> <p class="example-twitter"> <textarea name="fbwall" id="fbpost" class="" placeholder="whatzz upp?" > </textarea> <br/> <br/> <a href="#" class="button postfb" id="textpost">Post</a> </p> </form> </div> <br><br><br><br> <div id="viewpost"> <? $queyr=$db->query("select * from fb ORDER BY `id` DESC"); while($query=$db->fetch($queyr)) { ?> <div id="display"> <div id="leftdisplay"> <img src="http://lh3.googleusercontent.com/-Iw_xOyvn0z0/AAAAAAAAAAI/AAAAAAAAAFw/r_0QqjeH2vQ/s512-c/photo.jpg" width="120" height="120"/> </div><br/><br/> <div id="rightdisplay"> <p class="triangle-border left"> <? echo $query["wallpost"];?> </p> </div> </div> <div style="height:200px;"></div> <? } ?> </div> </div>
Ajax.php:
<? include 'class.php'; $db=new database(); $db->connect(); if(isset($_REQUEST["fbwall"])) { $wall=$_REQUEST["fbwall"]; $insert=$db->query("INSERT INTO fb (wallpost) VALUES ('$wall')"); if($insert) { $select=$db->query("select * from fb ORDER BY `id` DESC"); while($view=$db->fetch($select)) {?> <div id="display"> <div id="leftdisplay"><img src="http://lh3.googleusercontent.com/-Iw_xOyvn0z0/AAAAAAAAAAI/AAAAAAAAAFw/r_0QqjeH2vQ/s512-c/photo.jpg" width="120" height="120"/></div><br/><br/><br/><br/> <div id="rightdisplay"> <p class="triangle-border left"> <? echo $view["wallpost"];?> </p> </div> </div> <div style="height:200px;"></div> <? } } } ?>
Database: id---------->int(11) wallpost--->longtext()
class.php
<?
class database
{
public function connect()
{
$con=mysql_connect("localhost","root","") or die("unable to connect");
mysql_select_db("test",$con) or die("unable to select");
}
public function query($sql)
{
$sc=mysql_query($sql) or die("query not working". mysql_error());
return $sc;
}
public function fetch($qu)
{
$ft=mysql_fetch_array($qu);
return $ft;
}
public function num($rows)
{
$rw=mysql_num_rows($rows);
return $rw;
}
}
?>
Output:
No comments:
Post a Comment