Quostin Posted March 11, 2012 Share Posted March 11, 2012 I'm trying to show the same data, but updated right away. For example. I want to update my coords on a map and refresh a div to show the new data, but as the code now, it keeps the same data until I reload the page. Here is the code I have now. if ($north) { $ylocation = $users['y'] + 1; if ($ylocation > 5) { $ylocation = 0; } $locationyupdate = ("UPDATE players SET y = '$ylocation' WHERE name='$users[name]'"); mysql_query($locationyupdate) or die("could not register");?> <script type="text/javascript"> $('#npc').load('npc.php'); $('#description').load('description.php'); </script><?} The update code is before the reload script for the two div's. The data DOES change in the database, but the two div's won't display the new data until it is refreshed again. Do I need to reactivate fetch to get the new data? Quote Link to comment https://forums.phpfreaks.com/topic/258690-show-new-data-from-mysql-on-the-same-page-without-reloading/ Share on other sites More sharing options...
Quostin Posted March 11, 2012 Author Share Posted March 11, 2012 I'll try to be more clear. http://quostin.x10.mx/clone/ is my test. You would need to login to try it. test for username and testing for password. When you click North, you can see that the left side with location, description and picture will refresh, but the location is still the same. If you click north again, it will show a new location, but it would still be wrong by 1. the description div and npc div needs an exact location from the database to show the right thing to be display. I'm trying to have the data updated when it refreshes the div. I'm assuming that npc and description pages refreshes before the database is updated, even though the update piece of code is before the refresh on npc and description. Quote Link to comment https://forums.phpfreaks.com/topic/258690-show-new-data-from-mysql-on-the-same-page-without-reloading/#findComment-1326213 Share on other sites More sharing options...
cpd Posted March 11, 2012 Share Posted March 11, 2012 You can use Ajax to refresh your div's but as I mentioned in a different thread its an advanced technique for someone who has little understanding of PHP/ASP and JavaScript. You could also look into HTML web sockets but again it's a slightly more advanced feature of HTML which requires once again requires a knowledge of JavaScript. You might want to look into jQuery Ajax to make things a little easier. Quote Link to comment https://forums.phpfreaks.com/topic/258690-show-new-data-from-mysql-on-the-same-page-without-reloading/#findComment-1326221 Share on other sites More sharing options...
Quostin Posted March 12, 2012 Author Share Posted March 12, 2012 You can close this. I feel a little stupid now. I simply included $sql = mysql_query ("SELECT * FROM players where name='$username'"); $users = mysql_fetch_array($sql); right before the script to refresh the <div>... By reselecting the database, it grabs the newest data from the database... Again, I feel so stupid again. Quote Link to comment https://forums.phpfreaks.com/topic/258690-show-new-data-from-mysql-on-the-same-page-without-reloading/#findComment-1326254 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.