Arkadaşlar Selam,

PHP anlık güncelleme işlemi yaptım.sistem yalnızca <ul><li> yapısında doğru çalışıyor Ben tablo yapısına göre uyarlamaya çalışıyorum ama bir yerlerde yanlış yapıyorum o yüzden biraz döngünün içerisine giriyor.
Yardımcı olabilir misiniz? Kodları aşağıda vereyim.

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">
	<tr>
		<td>ID</td>
	</tr>
	<?php
	$query = $db->query("SELECT * FROM activity",PDO::FETCH_ASSOC);
	if($query -> rowCount())
		{
			foreach($query as $row){
				echo '
					<tr>
						<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"] = '<td>'.$row["author"].'</td>';
				}
			} else {
				$array["hata"] = "Yeni eklenmiş veri bulunmuyor!";
			}
		
		}
		echo json_encode($array);
?>

ajax.js
$(function(){
	
	$.ajaxLoad = function(){
		var lastid = $("tr td:first").attr("id");
		$.ajax({
			type: "post",
			url: "ajax.php",
			data: {"lastid":lastid},
			dataType: "json",
			success: function(cevap){
				
					$("td").prepend(cevap.veriler);
				
			}
		});
	}
	
	setInterval('$.ajaxLoad()', 1000);

});

Konunun aciliyeti vardır biraz arkadaşlar, yardımcı olursanız çok sevinirim.