Jump to content

Updating Page after Query


carrilo

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.