Jump to content

Archived

This topic is now archived and is closed to further replies.

Pi_Mastuh

What's wrong?

Recommended Posts

How would i take $fedtime and make it so that if it's more then 1 day away it adds 1 to hunger?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
What's wrong? My logic.

[code]if ($datelastfed < date("Y-m-d", strtotime("-1 day"))) {
echo "One hungry hippo";
}[/code]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.