antfuentes87 Posted June 21, 2011 Share Posted June 21, 2011 So I have a simple php while loop that loops through a table and displays the data. I want to integrate it with AJAX, so every time a new entry is added to the table, it automatically displays without having to refresh the page. $q = mysql_query("SELECT * FROM table"); while($f = mysql_fetch_array($q)){ echo $f['test_col']; } To be honest, I am not even sure if this is possible with AJAX (just started getting into it), but it seems like a good place to start. Any suggestions / help is much appreciated. I did Google this for awhile, but did not find anything (found things close, but nothing exactly like this). Link to comment https://forums.phpfreaks.com/topic/240024-php-while-loop-ajax/ Share on other sites More sharing options...
Alex Posted June 21, 2011 Share Posted June 21, 2011 That's not exactly how you would achieve what you're looking for. Here's one way you can get the effect that you're after: When the page loads have all the current entries listed output through PHP, and store the ID, for example, of the most recent entry in JavaScript. Create a PHP file that given an ID will return any entries added after that (e.g. SELECT ... FROM table WHERE id > $last_id). Then you can periodically query that page via AJAX, get any new entries and update the JavaScript variable that holds the ID of the last entry being displayed. Link to comment https://forums.phpfreaks.com/topic/240024-php-while-loop-ajax/#findComment-1233020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.