Worqy Posted April 5, 2010 Share Posted April 5, 2010 Hi. I'm making a little game, and I have done a bit progress in it. But now I want the player to chance to build some buildings. Here is the code: <?php Session_start(); if($_SESSION['LoginS1'] == false) { header('Location:login.php'); } else { // Include include ("config.php"); // ... $villageID = $_SESSION['villageID']; $fieldid = $_SESSION['fieldID']; $level = $_SESSION['level']; $field = "field1"; $nextlevel = $level + 1; // Connect to server and select database $connect = mysql_connect("$host","$username","$password")or die("cannot connect"); mysql_select_db("s1-prices")or die("cannot select Database"); $sql = mysql_query("SELECT * FROM $field WHERE level='$nextlevel'") or die(mysql_error()); while($data = mysql_fetch_array( $sql )) { $three = $data['three']; $clay = $data['clay']; $iron = $data['iron']; $wheat = $data['wheat']; $time = $data['time']; } // Close MySQL mysql_close($connect); $connect2 = mysql_connect("$host","$username","$password")or die("cannot connect"); mysql_select_db("s1-overall")or die("cannot select Database"); $sql2 = mysql_query("SELECT * FROM resources") or die(mysql_error()); while($data2 = mysql_fetch_array( $sql2 )) { if($data2['three'] > $three && $data2['clay'] > $clay && $data2['iron'] > $iron && $data2['clay'] > $clay) { // Three mysql_query("UPDATE resources SET three = three-$three"); //Clay mysql_query("UPDATE resources SET clay = three-$clay"); //Iron mysql_query("UPDATE resources SET iron = three-$iron"); //Wheat mysql_query("UPDATE resources SET wheat = three-$wheat"); echo "Done!"; echo "<br>"; echo "Time: " . $time; // Set in Time value to MySQL // Run buildsuccess.php when time is 00:00:00 } else { header('Location:build.php'); } } } ?> Now, as you see this code searches for the 'price' of the building and the time how long it takes to build it ( $time ). Now I need this script to but in the the time when the building is ready (ex: If the clock is now 12:00 and it takes 10min for the building to be ready, the time would be 12:10) That isn't maby the bigges thing, because I also need somekind of system that checks if the time is 12:00 (when the building is ready ( see example)). And this system need to run whatever the page is open or not... //Kevin Quote Link to comment https://forums.phpfreaks.com/topic/197606-need-help/ Share on other sites More sharing options...
ignace Posted April 5, 2010 Share Posted April 5, 2010 You possibly want to look at Ajax as altough PHP can track when a building is complete. You'll have to reload the page to verify with PHP that the building is truly complete. If you use a framework like jQuery it's really easy to apply Ajax calls. Quote Link to comment https://forums.phpfreaks.com/topic/197606-need-help/#findComment-1037072 Share on other sites More sharing options...
Worqy Posted April 5, 2010 Author Share Posted April 5, 2010 You possibly want to look at Ajax as altough PHP can track when a building is complete. You'll have to reload the page to verify with PHP that the building is truly complete. If you use a framework like jQuery it's really easy to apply Ajax calls. Okey, thank you. You know any specific Ajax tutorial/guide I would need to look at? Because I haven't used Ajax quite much, or to be exact, I havent used Ajax to anything. Quote Link to comment https://forums.phpfreaks.com/topic/197606-need-help/#findComment-1037101 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.