Jump to content

feelay

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

feelay's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey. This script is almost done, but something is stopping the value from updating.What I am trying to do is: I want the script to make the users HP update every minute. Here is the code: <?php $frequency = 60; $increment = 10; $current_time = time(); $last_update_time = mysql_result(mysql_query("SELECT `value` FROM `configuration` WHERE `name` = 'last_update'"), 0); $time_difference = $current_time - $last_update_time; $hours_passed = $time_difference / $frequency; $full_hours_passed = floor($hours_passed); $remaining_seconds = $time_difference % $frequency; if($full_hours_passed > 0){ $new_update_time = $current_time - $remaining_seconds; $hp_increase = $full_hours_passed * $increment; mysql_query("UPDATE `characters` SET `temphealth` = CASE WHEN `temphealth` + $hp_increase <= `maxhp` THEN `temphealth` + $hp_increase ELSE `maxhp` END WHERE `temphealth` > `maxhp`"); mysql_query("UPDATE `configuration` SET `value` = $new_update_time WHERE `name` = 'last_update'"); } if(isset($_SESSION['session..'])){ echo $current_time." current_time<br> ".$last_update_time." last_update_time<br>".$time_difference." time_difference <br>".$hours_passed." hours_passed<br> ".$full_hours_passed." full_hours_passed<br> ".$remaining_seconds." remaining_seconds<br> ".$new_update_time." new_update_time<br> ".$hp_increase." hp_increase<br>".$frequency." frequency<br> ".$increment." increment<br><br><br><br>";} ?> And here is the value for every Variable at 2 different times: The values changes all the time.
  2. I don't like cronjobs.. There must be another way.. Quote from another forum..
  3. Hello, Again. I am having a little problem with a time script. It is using the time() function, but I don't know how to use that function (I didn't create this script. a guy made it for me). The problem is, that the value is not updating in the database(it should update every 12 minutes, or every minute,depending on what i write in a place..) I guess that the fault is in the code somewhere.. but it is not in the queries.. I've tested them.. I can't find anything, but as I said, i don't know how this function works.. so can anyone please try to help me figure out whats wrong in this code: <?php $multiplier = 1 / 5; $frequency = 3600 * $multiplier; $increment = 5 * $multiplier; $current_time = time(); // get the current server time in second $last_update_time = mysql_result(mysql_query("SELECT hptime FROM characters"), 0); // This could be anywhere even in a separate text file! $time_difference = $current_time - $last_update_time; $hours_passed = $time_difference / $frequency; // convert sec to min then to hours --> 3600 second / 60 = 60 minutes / 60 = 1 hour $full_hours_passed = floor($hours_passed); // round the number of decimal hours down to the nearest whole hour $remaining_seconds = $time_difference % $frequency; // number of sec left when time difference is divided by 3600 sec --> 7 % 3 = 1 and 6 % 3 = 0 if($full_hours_passed > 0){ $new_update_time = $current_time + $remaining_seconds; $hp_increase = $full_hours_passed * $increment; mysql_query("UPDATE `characters` SET `temphealth` = CASE WHEN `temphealth` + $hp_increase <= `maxhp` THEN `temphealth` + $hp_increase ELSE `maxhp` END WHERE `temphealth` > `maxhp`"); mysql_query("UPDATE characters SET hptime = $new_update_time"); } ?>
  4. no idea how this will help.. but here you go.. UPDATE tbl SET temphealth = CASE WHEN temphealth + 0.0833333333333 <= maxhp THEN temphealth + 0.0833333333333 ELSE maxhp END CASE WHERE temphealth > maxhp
  5. This is from the php manual (http://se2.php.net/manual/sv/function.get-browser.php)
  6. is this what you mean?: Result: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHERE temphealth > maxhp' at line 1
  7. If this is what you are searching for, here you go: http://www.phpfreaks.com/forums/index.php/topic,181982.0.html
  8. If you mean that the user logs in from the "index page". and that if the user is logged in, show some texr, etc, else if the user is logged out, show login form, you will have to learn how to use sessions (or cookies, but sessions are more safe, i think) something like this.. index.php <?php if(isset($_SESSION['online'])){ echo "Welcome $_SESSION['online']"; } else{ ?> <form name="login_form" method="post" action="loginck.php"> <input name="user" type="text">ID<br /> <input name="pass" type="password">Password<br /> <input type="submit" name="login" id="login" value="Login"> </form> <?php } ?> and then the loginck.php should be something like this: <?php if (($_POST['user']==loginname) && ($_POST['pass']==password)){ $_SESSION['online']; header("location:index.php"); } else{ echo "Go away"; If that is what you wanted, then here you go. else if you just wanted to redirect, you can just use the folowing code: <?php header("location:file.php or whatever"); ?>
  9. I've tryed to echo the query (echo query or error). I got the error that i wrote in first post. maxhp is the maximum hp that a character level can have. both maxhp and temphealth is int 11. and yes. CASE is supported by mysql 5
  10. That wasn't the error =( This is how the code now looks, but still, it isn't working =/ <?php mysql_query("UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp WHERE temphealth < maxhp END CASE"); ?>
  11. <?php mysql_query("UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp WHERE temphealth < maxhp"); ?>
  12. Hey! I have a question. Whats wrong with the following query? I ran it in phpmyadmin, and this is what i get: SQL query: UPDATE tbl_name SET temphealth = CASE WHEN temphealth + $hp_increase <= maxhp THEN temphealth + $hp_increase ELSE maxhp WHERE temphealth < maxhp MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE temphealth < maxhp' at line 1 Any Idea? Thanks for any help. //Feelay
  13. ok.. some people on another forum helped me a bit.. but neither me or they can solve this problem.. The health keeps showing 1HP when the max is 280, and the hp should raise 5hp every 2 seconds.. Here is the code: <?php session_start(); include "database.php"; include "hptime.php"; include "level.php"; $nuser=mysql_real_escape_string($_SESSION['user']); $auser=mysql_real_escape_string($_SESSION['admin']); if($nuser){ $userfinal=$nuser; }elseif($auser){ $userfinal=$auser; } ################################################################# // TID $updatedR = mysql_query("SELECT hptime FROM characters WHERE user='$userfinal'"); //hämta förra tiden från databasen $updated = mysql_result($updatedR, 0, 'hptime'); $currentTime =time(); //tiden just nu $difference = $currentTime - $updated; // HP $healthR = mysql_query("SELECT temphealth FROM characters WHERE user='$userfinal'");//hp, etc. kan du nog fixa från annat värde som du hämtat. $health = mysql_result($healthR, 0, 'temphealth'); // HEAL $addHealth = floor($difference / 2); // we need to know how many hours have passed - we get an round value (though it is a "float" number) by using floor() $addHealth = (int) $addHealth * 5; // this is how much health will be added, if you add 5HP per hour - I'm not sure whether (int) is necessary, but better safe than sory $health += $addHealth; if ($health > $user['maxhp']) { $health = $user['maxhp']; } // we don't want the health to go over max hp! $updated = time(); // we also need to update the alteration time. mysql_query("UPDATE characters SET temphealth='$health' AND hptime='$updated' WHERE user='$userfinal'"); //Uppdatera HP och TIME ?> Thanks for any replie //Feelay
×
×
  • 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.