Jump to content

Why isn't it working?


Pi_Mastuh

Recommended Posts

I think the round script messes it up, now it says

Last Date Fed is 1158540243 seconds
Right now is 1158626813 seconds
# seconds since fed is 86570 seconds
Date last fed 2006-09-17 20:44:03
Date right now 2006-09-18 20:46:53
And the difference is 0 days

the difference should be 1 day because it was .9
[quote author=Pi_Mastuh link=topic=108390.msg436911#msg436911 date=1158627298]
I think the round script messes it up, now it says

Date last fed 2006-09-17 20:44:03
Date right now 2006-09-18 20:46:53
And the difference is 0 days

the 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.
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]<?php

include ("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 = 1158540243
echo "Last Date Fed is ". $then. " seconds<br/>"; // outputs

$right_now = time(); // in seconds since the start of time varies depending on when you test
echo "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]
This works:

[code]<?php
include ("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 testing
echo "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.
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 correct

If 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.

Archived

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

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