Jump to content


Photo

[solved]date help thank you.


  • Please log in to reply
5 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 25 August 2006 - 09:18 PM

Thank you.


Please can you help $months_payed_for 11 and 12 not working any advice please cheers.

all the other conditions with date work but 11 and 12 any idears cheers.

<?php

if($months_payed_for=="1"){

$d=date("d")+7;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£5";

}elseif($months_payed_for=="2"){


$d=date("d")+14;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£10";

}elseif($months_payed_for=="3"){


$d=date("d")+21;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£15";

}elseif($months_payed_for=="4"){


$d=date("d")+28;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£20";

}elseif($months_payed_for=="5"){


$d=date("d")+35;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£25";

}elseif($months_payed_for=="6"){


$d=date("d")+42;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);


$price="£30";

}elseif($months_payed_for=="7"){


$d=date("d")+49;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£35";

}elseif($months_payed_for=="8"){


$d=date("d")+56;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£40";

}elseif($months_payed_for=="9"){


$d=date("d")+63;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£45";

}elseif($months_payed_for=="10"){


$d=date("d")+70;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£55";

}elseif($months_payed_for=="11"){


$d=date("d")+77;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£60";

}elseif($months_payed_for=="12"){

$d=date("d")+94;
$exspire_date=date("$d-m-y");
$exspire_date=strtotime($exspire_date);

$price="£65";
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 25 August 2006 - 09:47 PM

I dont know why it doesnt work, but why dont you make your script nicer and shorter?

<?php
$d=date("d")+(7*$months_payed_for);
$exspire_date=strtotime(date("$d-m-y"));
$price="£".(5*$months_payed_for);
?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 25 August 2006 - 10:26 PM

i woluld like to but every condition is diffrent

how can i do this with mkdate please help

i tried a unix timestamp no luck yet.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 25 August 2006 - 10:55 PM

This is solved the only way i could come up with was using the time() stamp thanks to the grate php.net cheers all.


solved




<?php

if($months_payed_for=="1"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+7, date("Y", $now));

$price="£5";

}elseif($months_payed_for=="2"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+14, date("Y", $now));

$price="£10";

}elseif($months_payed_for=="3"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+21, date("Y", $now));
$price="£15";

}elseif($months_payed_for=="4"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+28, date("Y", $now));

$price="£20";

}elseif($months_payed_for=="5"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+35, date("Y", $now));

$price="£25";

}elseif($months_payed_for=="6"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+42, date("Y", $now));

$price="£30";

}elseif($months_payed_for=="7"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+49, date("Y", $now));

$price="£35";

}elseif($months_payed_for=="8"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+56, date("Y", $now));

$price="£40";

}elseif($months_payed_for=="9"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+63, date("Y", $now));

$price="£45";

}elseif($months_payed_for=="10"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+70, date("Y", $now));

$price="£55";

}elseif($months_payed_for=="11"){


$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+77, date("Y", $now));

$price="£60";

}elseif($months_payed_for=="12"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+94, date("Y", $now));

$price="£65";
}


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 25 August 2006 - 11:06 PM

Well, your definition of working must be different to mine

Take your "$months_paid_for = 1" case

$d = date('d')+7;
$exspire_date=date("$d-m-y");
echo $exspire_date;                  // ---> 32-08-06 !!!

I suggest you RTFM re date() format strings

Also if they pay for x months, why is the expiry date calculated by adding  7 * x days. There are 7 days in a week, not a month ???

As Orio pointed out, the price is the number of months * 5, until 10 months and above when an extra fiver gets added.

This might be closer
<?php
echo '<pre>';
for ($months_payed_for=1; $months_payed_for<=12; $months_payed_for++)  {
    $expire_date = date ('d-m-Y', strtotime("+$months_payed_for months"));
    $price = "£".(5*$months_payed_for);
    printf ('%2d %12s %5s<br>', $months_payed_for, $expire_date, $price);
}
echo '<pre>';

?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 25 August 2006 - 11:31 PM

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+77, date("Y", $now));

$price="£60";

}elseif($months_payed_for=="12"){

$now=time();
$exspire_date = mktime(0, 0, 0, date("m", $now)  , date("d", $now)+94, date("Y", $now));

$price="£65";


With your mathematical ability I really would recommend using PHP to calculate 12 * 7 and not hard-code the values. ;) (Or is the extra 10 days a deliberate bonus?)

If you just want to use the current time() values, date('m'), date('d') and date('Y') will suffice.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users