SoireeExtreme Posted February 9, 2007 Share Posted February 9, 2007 Ok, I'm working on a seemingly very easy explore/walking around script for a game. But each page loads the wrong info. On each page I have the location 100, 100 (latitude) (longitude). Now say I go north it does and loads the 101 to the database as it should. But when the page loads it doesn't update the location on the page it says 100. But if I go north again It will say 101 and not 102. So my question is how do I correct this in order to get the info that is loaded into the database to display correct instead of being off by one number each time? If you need more info please let me know thanks. This code is located at the top of the page, I've also tried it at the bottom. if($userstats3['latitude']) { $north="update ac_users set latitude=latitude+'1' where playername='$player'"; mysql_query($north) or die("Could not update latitude"); } This code is located in the middle of the page. Location: $userstats3[latitude], $userstats3[longitude] each of these are in their own <?php ?> along with other coding of course. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 Where is userstats coming from? the session? Do you query the database each time? You'll need to update that array after the update. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted February 9, 2007 Author Share Posted February 9, 2007 I update the database like this... And down in the middle of the page. When I display the location from the database I use the same thing here except its in its own <??> using the player userstats from the top of the page. <?php if (isset($_SESSION['player'])) { $player=$_SESSION['player']; $userstats="SELECT * from ac_users where playername='$player'"; $userstats2=mysql_query($userstats) or die("Could not get user stats"); $userstats3=mysql_fetch_array($userstats2); if($userstats3['latitude']) { $north="update ac_users set latitude=latitude+'1' where playername='$player'"; mysql_query($north) or die("Could not update latitude"); } } else { echo "<META HTTP-EQUIV = 'Refresh' Content = '1; URL =../index.php'>"; die("Sorry not logged in. Redirecting Now!"); } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 You select their stats before updating them. After you update the stats in the database, you also need to update your $userstats. Try changing it to +1, not +'1' Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted February 9, 2007 Author Share Posted February 9, 2007 Try changing it to +1, not +'1' Didn't do nothing. Doing the same thing Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 Do you have PHP MyAdmin or some tool like that? Look in the database and make sure it's updating. print $north before running it to make sure it says what you want. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted February 9, 2007 Author Share Posted February 9, 2007 yeah I've already check that database and it updates. and then it does say what I want, but it says it later, when I click north it says 100 when it should say 101. even though the database reads 101 but the page doesn't when loaded. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2007 Share Posted February 9, 2007 As I said twice, you need to SELECT the information AFTER updating it. Not before. 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.