How to return latest Mysql entry through JQuery/Ajax request

actionfiguresxz

New Member
I am trying to pull the latest entry of a mysql table through ajax and display it as html content inside a div. I have ajax and php functioning correctly, the only problem I have is that I want to query for new entries and stack the results at a time interval within a loop and I've run into two problems: getting the data to behave like a normal javascript string, and getting the loop to only return unique entries.update.php file\[code\]$con=mysqli_connect("mydbhost.com","username","password","database_name");// Check connectionif (mysqli_connect_errno()){echo "Failed to connect to MySQL: " . mysqli_connect_error();}$result = mysqli_query($con,"SELECT * FROM conversations");$j = 0;while($row = mysqli_fetch_array($result)){$carray[j] = $row['comment'];$j++;}$comment = (array_pop($carray));echo $comment;echo "<br>";mysqli_close($con);\[/code\]JQuery Ajax request loop:\[code\]$(document).ready(function(e){ var comment; function commentLoop() { comment = $('#testdiv').load('update.php'); $('#testdiv').append(comment); setTimeout(commentLoop, 6000); } commentLoop(); $(document).focus();});\[/code\]
 
Back
Top