Jump to content

Show new data from MySQL on the same page without reloading


Quostin

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.