Jump to content

Archived

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

Pi_Mastuh

Why isn't it working?

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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
It produces

Date last fed
Date right now 2006-09-18 22:49:50
And the difference is 1 days

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

Share this post


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

Share this post


Link to post
Share on other sites
The problem is obviously that it's not recieving the variable correctly. Is there an error in my SQL query or something?

Share this post


Link to post
Share on other sites
I got it to work. i simply added "as lastDatefed" to my query, the variable wasn't declared.

Share this post


Link to post
Share on other sites
I'm pleased you got it to work  ;D

I'm sure you've learned a lot in this exercise and the one before.  Good luck with your future scripting endeavours.

Share this post


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

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.