Jump to content

What's wrong?


Pi_Mastuh

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.