Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 How would i take $fedtime and make it so that if it's more then 1 day away it adds 1 to hunger? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 Depends on the format of $fedtime in your database.Basically you need to retrieve $fedtime; determine today's date; if they're significanylt different, incremnent hunger and write to database.Try and do that yourself. Post back - with code - if your efforts are unsuccessful. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 i'm using [code]$query = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'"; $result = mysql_query($SQL,$connection); $query_data = mysql_fetch_array($result); $lastDatefed = $query_data['lastDatefed'];$timespan = strtotime("$today - $lastDatefed");$hours = strtotime("1 day");if ($timespan >= $hours); { $hunger++; mysql_query("UPDATE chibifriendspets SET hunger = '$hunger' WHERE monopetID = '".$_POST['monopetID']."'"); }[/code]But noting happens. The lastDatefed for the pet i'm using to test it is 2006-08-29, which is a lot more then 24 hours from today. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 It always helps debug if you echo out variables from time to time. If you add a line like echo $timespan after you 'calculate' it, you'll see just what the problem is ...I think what you really want in order to compare with yyyy-mm-dd dates is something like:[code]if (date("Y-m-d", strtotime("-1 day")) < $lastDatefed) { echo "ooooo, I'm hungry"; // or whatever you want to do}[/code] Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 16, 2006 Author Share Posted September 16, 2006 Nothing happens, I'm using [code]<? $query = "SELECT * FROM chibifriendspets WHERE monopetID = '$monopetID'"; $result = mysql_query($SQL,$connection); $query_data = mysql_fetch_array($result); $lastDatefed = $query_data['lastDatefed']; $hunger = $query_data['hunger'];$timespan = strtotime("$today - $lastDatefed");$hours = strtotime("1 day");if (date("Y-m-d", strtotime("-1 day")) < $lastDatefed) { echo "I'm hungery"; $hunger++; // or whatever you want to do mysql_query("UPDATE chibifriendspets SET hunger = '$hunger' WHERE monopetID = '".$_POST['monopetID']."'"); } ?>[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 What's wrong? My logic.[code]if ($datelastfed < date("Y-m-d", strtotime("-1 day"))) {echo "One hungry hippo";}[/code] Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 17, 2006 Author Share Posted September 17, 2006 Now it increases their hunger even if you fed them today. It also doesn't update the time last fed. For that I'm using:[code]$today = strtotime("today");if ($food == "Food"){$hunger--; mysql_query("DELETE FROM myitemschibi WHERE itemID = '".$_POST['itemID']."'");mysql_query("UPDATE chibifriendspets SET lastDatefed = '$today' WHERE monopetID = '".$_POST['monopetID']."'");[/code] Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 17, 2006 Author Share Posted September 17, 2006 I'm trying to get it so that you use food on them and it decreases their hunger, but it increases by 1 if you havn't fed tem for 24 hours. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 17, 2006 Author Share Posted September 17, 2006 It also is decreasing for all of the user's pets instead of just the 1 they click on. Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted September 17, 2006 Author Share Posted September 17, 2006 Do you know what's wrong? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 17, 2006 Share Posted September 17, 2006 No idea what's wrong as we're not looking at the whole script exactly as you have it in it's "not quite working" state. Take a careful look at your logic, your database queries, and any conditional structures in your script and that should give you some clues.Remember that while debugging, it's worthwhile echoing all queries so you can see exactly what the querystrings are (not always what you think they should be), and include error traps on all the mysql_query statements. How to do both is strewn through this thread as examples. 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.