Denermisin.
Ayrica yeni kayit eklerken satir olarakmi eklemek istiyorsun yoksa td olarak yan yana mi eklemek istiyorsun ? ben tr yani yeni satir olarak duzenledim, normalde calismasi lazim ama hatayi console den kontrol ederek duzeltebilirsin.
index.php
<?php require "connections.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<table border="1" id="sonuc">
<tr>
<td>ID</td>
</tr>
<?php
$query = $db->query("SELECT * FROM activity",PDO::FETCH_ASSOC);
if($query -> rowCount())
{
foreach($query as $row){
echo '
<tr id="tr_'.$row["aID"].'">
<td>'.$row["author"].'</td>
</tr>';
}
}
?>
</table
<!--<div id="sonuc"></div>-->
</body>
</html>
ajax.php
<?php
require_once "connections.php";
if ($_POST){
$lastid = $_POST["lastid"];
if (!$lastid){
$array["hata"] = "Geçersiz işlem!";
} else {
$query = $db->query("SELECT * FROM activity WHERE aID > $lastid ORDER BY aID DESC",PDO::FETCH_ASSOC);
if($query -> rowCount())
{
foreach($query as $row){
$array["veriler"] = '<tr id="tr_'.$row["aID"].'"><td>'.$row["author"].'</td></tr>'; // duzenlendi
}
} else {
$array["hata"] = "Yeni eklenmiş veri bulunmuyor!";
}
}
echo json_encode($array);
?>
ajax.js
$(function(){
$.ajaxLoad = function(){
var lastid = $("tr:last").attr("id"); // duzenlendi
$.ajax({
type: "post",
url: "ajax.php",
data: {"lastid":lastid},
dataType: "json",
success: function(cevap){
$("#sonuc").append(cevap.veriler); // duzenlendi
}
});
}
setInterval('$.ajaxLoad()', 1000);
});