Jump to content

[solved]help with working out this code with dates and months and price cheers.


redarrow

Recommended Posts

a user joins my site the user has got to select what amount of months that the user wants to subcribe to the website for each month cost 5 pound,

i need to use an update query to tell the database of the number of moths that the user has choose and update the database according to the price and also add the exspire date.

can you kindly tell me is there a shorter way then this code please cheers.

this is the short version for 5 months cheers.

example
if the user choose 4 months the members table updates the price and exspire_date.

[code]
<?php

database connection


$query1="select payment_months, exspire_date from members where id=$id";
$result1=mysql_query($query1);


while($payment_months=mysql_fetch_assoc($result1)){

$months=$payment_months['payment_months'];


if($months==1){

$exspire_new=$payment_months['exspire_date']+2629743.83;

$query2="update members set payment_months=5,exspire_date=$exspire_new where id=$id ";

$result2=mysql_query($query2);  



}elseif($month==2){

$exsipre_new=$payment_months['exspire_date']+5259487;

$query3="update members set  payment_months=10,exspire_date=$exspire_new where id=$id   

$result3=mysql_query($query3);



}elseif($month==3){

$exsipre_date=$payment_months['exspire_date']+7889231.49;

$query=4"update members set  payment_months=15,exspire_date=$exspire_new where id=$id   



$result4=mysql_query($query4);

}elseif($month==4){

$exsipre_new=$payment_months['exspire_date']+10518975.3;

$query5="update members set payment_months=20,exspire_date=$exspire_new where id=$id   

$result5=mysql_query($query5);



}elseif($month==5){

$exsipre_new=$payment_months['exspire_date']+13148719.2;

$query6="update members set payment_months=25,exspire_date=$exspire_new where id=$id   

$result6=mysql_query($query6);

}
  }

[/code]



solved

thanks for the code andy cheers.

[code]
<?php

$db=mysql_connect("localhost","xxx","xxx");
mysql_select_db("testcode",$db);


$query1="select payment_months, exspire_date from members where id=2 ";
$result1=mysql_query($query1);


while($payment_months=mysql_fetch_assoc($result1)){

$months=$payment_months['payment_months'];



if($months==1){

$exspire_new=$payment_months['exspire_date']+2629743.83;

$query2="update members set payment_months=5,exspire_date=$exspire_new where id=2 ";

$result2=mysql_query($query2); 



}elseif($months==2){

$exspire_new=$payment_months['exspire_date']+5259487;

$query3="update members set  payment_months=10,exspire_date=$exspire_new where id=2";   

$result3=mysql_query($query3);



}elseif($months==3){

$exspire_new=$payment_months['exspire_date']+7889231.49;

$query4="update members set  payment_months=15,exspire_date=$exspire_new where id=2"; 

$result4=mysql_query($query4);



}elseif($months==4){

$exspire_new=$payment_months['exspire_date']+10518975.3;

$query5="update members set payment_months=20,exspire_date=$exspire_new where id=2";   

$result5=mysql_query($query5);



}elseif($months==5){

$exspire_new=$payment_months['exspire_date']+13148719.2;

$query6="update members set payment_months=25,exspire_date=$exspire_new where id=2";   

$result6=mysql_query($query6);

}
  }
?>
[/code]

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.