• 12-06-2016, 09:46:18
    #1
    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.
  • 12-06-2016, 12:58:05
    #2
    Üyeliği durduruldu
    Sorunu tam bir şekilde açıklarsanız yardımcı olayım hocam. Skype : NippyBoys @ercnakar
  • 12-06-2016, 17:58:22
    #3
    ekledim
  • 13-06-2016, 12:59:04
    #4
    yadımcı olabilecek varmı??
  • 13-06-2016, 13:58:31
    #5
    Üyeliği durduruldu
    oncelikle table e bir id ver

    sonra
    mantik dogru ancak ul li de prepend kullaniyorsun , tabloda ise su formatta yapman lazim
    $('#myTable tr:first').after($tr);
  • 14-06-2016, 12:39:53
    #6
    propertyandturk adlı üyeden alıntı: mesajı görüntüle
    oncelikle table e bir id ver

    sonra
    mantik dogru ancak ul li de prepend kullaniyorsun , tabloda ise su formatta yapman lazim
    $('#myTable tr:first').after($tr);

    sanırım çalışmadı
  • 14-06-2016, 13:15:34
    #7
    Üyeliği durduruldu
    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);
    
    });
  • 14-06-2016, 14:09:47
    #8
    musti_com adlı üyeden alıntı: mesajı görüntüle
    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);
    
    });
    kontrol etti ancak hocam çalışmıyor
  • 14-06-2016, 20:11:46
    #9
    Üyeliği durduruldu
    O zaman CTRL + SHIFT + L (chrome) yapip, console kismini acin ve ordaki hatalari buraya yazin..