Re: how to simplify my code - I will have tooo many lines -pleasehelp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Shawn McKenzie wrote:
> Wow!  Yes, there are a lot of ways to do it.  This is a quick stab (not
> tested):
> 
> $Today = date('m/d/y');
> 
> if ( $selectedProdCode == "agreem" && $errorArray['agr1expdate'] < $Today)
> {
> 	$selectedProdCode= //agreement cost + late fee
> } else {
> 	$selectedProdCode= //agreement cost
> }
> if ( $selectedProdCode == "agreem2" && $errorArray['agr1expdate'] >= $Today
> && $errorArray['agr2expdate'] >= $Today )
> {	
> 	$selectedProdCode= //agreement cost * 2
> }
> elseif ( $selectedProdCode == "agreem2" && ($errorArray['agr1expdate'] <
> $Today || $errorArray['agr2expdate'] < $Today) )
> {	
> 	if ( $errorArray['agr1expdate'] < $Today && $errorArray['agr2expdate']
> < $Today )
> 	{
> 		$selectedProdCode= //(agreement cost * 2) + (late fee *2)
> 	} else {
> 		$selectedProdCode= //(agreement cost * 2) + late fee
> 	}		
> }
> 
Here's another stab (not tested).  Also, in my previous post I just
copied your code, there should be == instead of = in the if expressions.

$Today = date('m/d/y');
$Agreements = 0;
$lateFees = 0;

if ( $selectedProdCode == "agreem" )
{
	$Agreements = 1;
}
elseif ( $selectedProdCode == "agreem2" )
{
	$Agreements = 2;

	if ( $errorArray['agr2expdate'] < $Today )
	{
		$lateFees++;
	}
}
if ( $errorArray['agr1expdate'] < $Today )
{
	$lateFees++;
}
$selectedProdCode= //(agreement cost * $Agreements) + (late fee * $lateFees)

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux