Page 1 of 1

Doing math on mktime

Posted: Sat Mar 21, 2009 9:05 am
by vbmark
Hello,

I am storing the value of mktime in the endingdate column which is a bigint(20) unsigned field. I can get the value out just fine, but when I do math on it it overwrites. Here's what I'm doing: (using Database.class.php)

Code: Select all

$sql = "SELECT endingdate FROM mytable WHERE id='".$id."'";
$row = $db->query_first($sql);
 
if ($row['endingdate'] != "") {
    $days = 86400 * $days;
    $endingdate += $days;
    $daysinfo['endingdate'] = $endingdate;
    $db->query_update("mytable", $daysinfo, "id='".$id."'");
}
This is driving me nuts :banghead:

I cannot troubleshoot this the normal way because this is in my Paypal ipn return script. So I cannot echo anything to the screen. Any ideas?

Thanks!

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 12:02 pm
by php_east
is it right to have $daysinfo array in the update field, or should it be $daysinfo['endingdate'] ?

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 12:08 pm
by vbmark
php_east wrote:is it right to have $daysinfo array in the update field, or should it be $daysinfo['endingdate'] ?
Yes, from the documentation that field takes an "assoc array with data".

Thanks though

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 9:27 pm
by vbmark
I have simplified the problem even more. Someone has to be able to tell me why this is happening.

Code: Select all

$sql = "SELECT endingdate FROM mytable WHERE id='".$id."'";
$row = $db->query_first($sql);
 
if ($row['endingdate'] != "") {
  echo "endingdate1: ".$row['endingdate']."<br />";
  $endingdate = $endingdate + 1;
  echo "endingdate2: ".$endingdate."<br />";
}
Here are the results:

Code: Select all

endingdate1: 1237694670
endingdate2: 1
Why is endingdate2 echoing 1 when it should be 1237694671?

Thanks!

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 9:30 pm
by vbmark
Aaaaaaaaaaahhhhhhhhhhh, I GOT IT!!!!

Never mind :crazy:

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 10:11 pm
by php_east
:wink: string+numeric maybe.

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 10:22 pm
by vbmark
Nope. The answer is just staring you in the face. Don't feel bad, it took me about 4 hours to figure it out.

It is easier than you think.

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 10:32 pm
by php_east
ah yes, if it was a snake you would have been bitten.
$endingdate = $endingdate + 1;

$endingdate=null :)

i don't feel bad, just curious. things like this catches us all the time, even the seasoned ones.

Re: Doing math on mktime

Posted: Sat Mar 21, 2009 10:36 pm
by vbmark
Yup. I just can't believe how much time I wasted on this.

I was googling eveything I could find about mktime.

Oh well. I can get on with my life now. :)