carrilo Posted March 5, 2014 Share Posted March 5, 2014 I have a page asistencia.php which displays the monthly attendance of students at my school. The attendance is stored in a mysql data base. When I need to update the attendance I click on the number displayed, it opens the page editasitencia.php. Once it is updated it processes this bit of code if (mysql_affected_rows() ==1) { echo'<h1 id="mainhead"> Update Asistencia</h1> <p> The asistencia has been updated</p><p> <br /><br /></p>'; } I then have to reverse back to the original page asistencia.php and reload it in order to see the updated attendance. Is there a way that I can make it automatically reload the page asistencia.php once I have executed the update query? Quote Link to comment https://forums.phpfreaks.com/topic/286721-updating-page-after-query/ Share on other sites More sharing options...
sKunKbad Posted March 5, 2014 Share Posted March 5, 2014 You could use AJAX to send the details of the update (your form submission) to a processing script, which would return the updated data. You would simply replace the current data with the updated data. jQuery makes this really easy, but it can be done using plain JavaScript or nearly any other JS framework. Quote Link to comment https://forums.phpfreaks.com/topic/286721-updating-page-after-query/#findComment-1471517 Share on other sites More sharing options...
carrilo Posted March 5, 2014 Author Share Posted March 5, 2014 Thanks - do you know where I could see an example? I have no idea how to do this. Quote Link to comment https://forums.phpfreaks.com/topic/286721-updating-page-after-query/#findComment-1471536 Share on other sites More sharing options...
gizmola Posted March 5, 2014 Share Posted March 5, 2014 While there are places for Ajax, I don't think it's called for in this case. A typical solution is to use a "flash message". You can easily implement something like this with Twitter Bootstrap, and php sessions. Basically, the idea is that your edit script will do the update, set a session variable with the "Flash message" and redirect using header("Location: ..."); Your markup of your asistencia.php page, then simply needs to include some code that checks for the existence of the session variable, and if it does exist, displays the Message Box at the top of the asistencia.php page. You can create something like this by hand of course, but if you don't already have some helpers, bootstrap might be a helpful addition. At very least, these alerts will give you an example of what you're trying to achieve: http://getbootstrap.com/components/#alerts Typically you make them "dismissible" so that the user can click on the x to dismiss the message. You can generalize inter-page navigation and errors using this idea. Quote Link to comment https://forums.phpfreaks.com/topic/286721-updating-page-after-query/#findComment-1471540 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.