Pi_Mastuh Posted September 19, 2006 Author Share Posted September 19, 2006 I think the round script messes it up, now it saysLast Date Fed is 1158540243 secondsRight now is 1158626813 seconds# seconds since fed is 86570 secondsDate last fed 2006-09-17 20:44:03Date right now 2006-09-18 20:46:53And the difference is 0 daysthe difference should be 1 day because it was .9 Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94338 Share on other sites More sharing options...
AndyB Posted September 19, 2006 Share Posted September 19, 2006 [quote author=Pi_Mastuh link=topic=108390.msg436911#msg436911 date=1158627298]I think the round script messes it up, now it saysDate last fed 2006-09-17 20:44:03Date right now 2006-09-18 20:46:53And the difference is 0 daysthe difference should be 1 day because it was .9[/quote]No, it should be 1 because - as you can see from the dates and times - [b]more[/b] than 24 hours have passed. Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94342 Share on other sites More sharing options...
Pi_Mastuh Posted September 19, 2006 Author Share Posted September 19, 2006 That's what I'm saying, it should be 1 but it says 0.Do you know why it's doing that? Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94346 Share on other sites More sharing options...
Pi_Mastuh Posted September 19, 2006 Author Share Posted September 19, 2006 I got it to round but now it's not working at all, it just says that the lastdatefed was today when it's the 15th.I modified the test code to include the lastdatefed from the database. Here's what I have:[code]<?phpinclude ("secure/config.php");include ("secure/dbinfo.php");$query = "SELECT * FROM chibifriendspets WHERE monopetID = '1'"; $result = mysql_query($query ,$connection); $query_data = mysql_fetch_array($result); $lastDatefed = $query_data['lastDatefed'];$lastDatefed = date("Y-m-d H:i:s",strtotime("$lasteDatefed")); // your database value$then = strtotime($lastDatefed); // in seconds since the start of time = 1158540243echo "Last Date Fed is ". $then. " seconds<br/>"; // outputs $right_now = time(); // in seconds since the start of time varies depending on when you testecho "Right now is ". $right_now. " seconds<br/>"; // outputs $timesincefed = $right_now - $then;echo "# seconds since fed is ". $timesincefed. " seconds<br/>";$dayssincefed = number_format($timesincefed/86400,2);$days = round($dayssincefed);echo "Date last fed ". $lastDatefed. "<br/>Date right now ". date("Y-m-d H:i:s"). "<br/>And the difference is ". $days. " days";?>[/code] Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94363 Share on other sites More sharing options...
Pi_Mastuh Posted September 19, 2006 Author Share Posted September 19, 2006 do you see anything wrong with my code? Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94369 Share on other sites More sharing options...
AndyB Posted September 19, 2006 Share Posted September 19, 2006 This works:[code]<?phpinclude ("secure/config.php");include ("secure/dbinfo.php");$query = "SELECT * FROM chibifriendspets WHERE monopetID = '1'"; $result = mysql_query($query ,$connection); $query_data = mysql_fetch_array($result); $lastDatefed = $query_data['lastDatefed'];// remove this when you finish testing$lastDatefed = "2006-09-15 11:00:00"; $then = strtotime($lastDatefed);$right_now = time();$timesincefed = $right_now - $then;$dayssincefed = number_format($timesincefed/86400,2);$days = round($dayssincefed);// remove this when you finish testingecho "Date last fed ". $lastDatefed. "<br/>Date right now ". date("Y-m-d H:i:s"). "<br/>And the difference is ". $days. " days";?>[/code]Then try removing the line where I force the lastDatefed to 2006-09-15 11:00:00 and run it again. If it doesn't produce 3 days then the date in your database isn't what you think. Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94377 Share on other sites More sharing options...
Pi_Mastuh Posted September 19, 2006 Author Share Posted September 19, 2006 It produces Date last fedDate right now 2006-09-18 22:49:50And the difference is 1 daysBut I'm POSITIVE that the lastdatefed for the pet with an ID of 1 is 2006-09-15 10:30:20. I just copied that from the database so I know it's right. Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94387 Share on other sites More sharing options...
AndyB Posted September 19, 2006 Share Posted September 19, 2006 If that's what it produces, then what you think about the database can't be right, can it?Are you sure that:#1 - all of the current scripts have been uploaded to your server in the right folders#2 - your current scripts are using the same database and same table name as you want them to#3 - the database value for the record you're sure you're reading is correctIf the answer to all of those is yes, then it's illogical, irrational, inexplicable, and I give up. I can't see how a database value generates one result and declaring the same variable with the same value as you claim is in the database can come up with a different result. Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94548 Share on other sites More sharing options...
Pi_Mastuh Posted September 19, 2006 Author Share Posted September 19, 2006 The problem is obviously that it's not recieving the variable correctly. Is there an error in my SQL query or something? Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94916 Share on other sites More sharing options...
Pi_Mastuh Posted September 19, 2006 Author Share Posted September 19, 2006 I got it to work. i simply added "as lastDatefed" to my query, the variable wasn't declared. Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94926 Share on other sites More sharing options...
AndyB Posted September 19, 2006 Share Posted September 19, 2006 I'm pleased you got it to work ;DI'm sure you've learned a lot in this exercise and the one before. Good luck with your future scripting endeavours. Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94971 Share on other sites More sharing options...
Pi_Mastuh Posted September 20, 2006 Author Share Posted September 20, 2006 Thank you for all your help ;D. I love these forums. Last month I would have looked at these scripts and said "huh...?" and now I actualy know what they mean and how to write them and everything ;D Link to comment https://forums.phpfreaks.com/topic/21061-why-isnt-it-working/page/2/#findComment-94984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.