I'm making a real-time feedback system & I need to know how to make the viewing page refresh automatically (or show new row) when a new row gets added to a MySQL database.
Here's what my system does:
- Somebody writes into a form (index.php)
- the data goes into a MySQL database
- I can view what they wrote (display.php)
I want to know how to make display.php automatically reload when somebody writes in the index.php forms.
You would have to check at a certain interval for new data. This is probably best done via AJAX to avoid constant page reloads. You could also insert new data into display.php without a reload this way too.
I think the display.php must return the xml or json, and you must put the last database id in the xml, and your ajax request must send the last id record that they have:
display.php xml
Code:
<data>
<rowsdata>your data in here</rowsdata>
<lastid>10</lastid>
</data>
And in the html view model you can put this
Code:
<div id='showtheresult'> <!-- we will use this div for getting the result -->
your html code for show
</div>
In javascript when success get the result from display.php you can use
Code:
$("#showtheresult").append("the rowsdata value from xml");
How would I implement this? I tried, but failed. It displayed everything & it still worked, but when I entered sent in data from the index.php file, it didn't reload. I left it for 5 minutes & nothing. So, how would I implement this? (display.php is written in an above post from me)
Bookmarks