mattd8752 Posted February 24, 2007 Share Posted February 24, 2007 Ok, just so you know, I am NOT entering the contest. This IS my first class, so I am quite sure it is something small, but if someone can help: <?php class research { var $z; var $update; function set_time($x){ $this->z = $x; } function update(){ $lastvisit = date("M-d-Y H:m:s a", time()); $diff = $this->z; $nextup = $lastvisit+$diff; $timenow = time(); if ($timenow > $nextup) { $this->update = "yes"; } else { $this->update = "no"; } } function calc(){ if($this->update == "yes"){ echo "Update!"; } } } $myvar = new research; $myvar->set_time("600");//10 mins $myvar->update(); $myvar->calc(); ?> Can you see why it says update! all of the time. It shouldn't say update, EVER according to this script. Also, how would I check how many sets of 600seconds or 10 minutes there are between two times, thats something I want to add to calc();. Yes this is for a mmorpg, no, I am NOT entering the contest. Thanks, Matt Link to comment https://forums.phpfreaks.com/topic/39872-my-first-class-mmorpg-related-i-am-not-entering-the-contest/ Share on other sites More sharing options...
JBS103 Posted February 24, 2007 Share Posted February 24, 2007 You are adding: Feb-23-2007 17:02:23 pm + 600 And obviously it can't make any sense out of that so, $nextup = 600. So that if is always going to check out as "yes". I'm not totally sure what you are trying to do, but you want to do $time+600 if anything. However, this will always be the same too ("No")... Can you explain what the update function is doing and what the point of $lastvisit is? If you want to do a calculation between two times, you do $time1 = 400; //In seconds $time2 = 1000; //In seconds $result = ($time2 - $time1) / 60; //In this case $result = 10 time() returns the number of seconds after the Unix Epoch. You don't really need to worry about that, but for this application, it will essentially tell you how many seconds elapsed, and from that you can determine how many minutes are in between. Link to comment https://forums.phpfreaks.com/topic/39872-my-first-class-mmorpg-related-i-am-not-entering-the-contest/#findComment-192655 Share on other sites More sharing options...
mattd8752 Posted February 24, 2007 Author Share Posted February 24, 2007 It could be days between the times, it could be months. It is checking the last time they logged in Vs. This time. It is basically checking how many "updates" have passed. Link to comment https://forums.phpfreaks.com/topic/39872-my-first-class-mmorpg-related-i-am-not-entering-the-contest/#findComment-192664 Share on other sites More sharing options...
JBS103 Posted February 24, 2007 Share Posted February 24, 2007 Okay, but right now, $lastvisit and $timenow are the exact same thing displayed in two different ways. $lastvisit = date("M-d-Y H:m:s a", time()); $timenow = time(); Link to comment https://forums.phpfreaks.com/topic/39872-my-first-class-mmorpg-related-i-am-not-entering-the-contest/#findComment-192669 Share on other sites More sharing options...
emehrkay Posted February 24, 2007 Share Posted February 24, 2007 are you running php5, if so, ,you need to update how you structure your class. if you're running four, i say that you need to change your set_time method to be a real constructor by naming it research. that way when you call the class, you can pass the 600 val without having to call a seperate method class research{ function research($val){ $this->val = $val; } } $x = new research(600); and jbs is absolutely correct. you're adding an integer to a string. you need to convert $lastvisit to an integer before you add the property z ($this->z) Link to comment https://forums.phpfreaks.com/topic/39872-my-first-class-mmorpg-related-i-am-not-entering-the-contest/#findComment-192746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.