RealDrift Posted August 12, 2009 Share Posted August 12, 2009 Hi, Basically I have a table displaying a simple word in a table. this word is pulled from a mysql table. Below this I have a textbox where you can type in a new word and then click submit, which updates the sql table. When the submit button is pressed and the old word is replaced by the new one in the table a message is echoed stating so. When this is echoed I want the table to show the new word that just replaced the old one. Currently the message is echoed and the table shows the old word. I have to manualy refresh the page and then the new word is shown in the table. Any help will be appreciated, I just can't seem to find an answer. Thanks a lot Quote Link to comment Share on other sites More sharing options...
RealDrift Posted August 12, 2009 Author Share Posted August 12, 2009 anyone? Quote Link to comment Share on other sites More sharing options...
RealDrift Posted August 13, 2009 Author Share Posted August 13, 2009 i need help on this, if anyone could Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 There is many options.. two comes in mind now. First if and think you do fetch the word from db when thepage is loaded, you could just use header() and redirect the user after submit to the same page. In this way the new word would appear since the page is loaded automatically again. Or you can use AJAX to update the table in real time, which is a little more complex to do. Quote Link to comment Share on other sites More sharing options...
darcyf1.com Posted August 13, 2009 Share Posted August 13, 2009 What order do you have your functions in? Make sure you have: { //do update database here } { //retrieve 'word' from database here } That way you'll be putting the new word in, before getting that new word out. Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 What order do you have your functions in? Make sure you have: { //do update database here } { //retrieve 'word' from database here } That way you'll be putting the new word in, before getting that new word out. This would work also, but redirect would be good because if the user refreshes the page the word is submitted again and new query will be done with the same values which means useless db queries. And in the worst case scenario if there is multiple users changing the word: mr A submits a word, then mr B submits new word, then A refreshes and mr B's new word is replaced with the mr A's old word. But don't know if this is the case. Quote Link to comment Share on other sites More sharing options...
RealDrift Posted August 14, 2009 Author Share Posted August 14, 2009 thanks for your help, i have already arranged the script like you have mentioned. the mysql gets updated in the beginning of the script and then i fetch the word from the db. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 You will need AJAX to make it dynamic like you want without having to refresh the page. PHP won't be able to change the word without a refresh. even using a header or something like that is only a cosmetic change, as it still needs to refresh. Depending on the code, you may be able to use pretty simple javascript also, but I don't know how your script works, So i can't really say Quote Link to comment Share on other sites More sharing options...
RealDrift Posted August 14, 2009 Author Share Posted August 14, 2009 shouldn't the word be updated after the user presses submit? I mean the submit button reloads the script which runs all the code again meaning the word is fetched from the db again which should be updated and hence the new word should show? Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 Oh? if thats the case then yes. post your code maybe? Quote Link to comment 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.