redarrow Posted August 15, 2006 Share Posted August 15, 2006 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.exampleif the user choose 4 months the members table updates the price and exspire_date.[code]<?phpdatabase 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] Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 15, 2006 Share Posted August 15, 2006 [code]// $months = number of months they wantlist($y,$m,$d) = explode("-",date("Y-m-d")); // what's today?$exspire_date = date("Y-m-d", mktime(0,0,0,$m+$months,$d,$y));[/code]Maybe that'll help Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 15, 2006 Author Share Posted August 15, 2006 solvedthanks 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.