Link to home
Start Free TrialLog in
Avatar of hej613
hej613

asked on

PHP Large "IF" statement

Good Afternoon Experts, I have a fairly large "IF" statement that I could use some help on.

The idea is I need to loop through our jail database and calculate the time each person has been in jail, my code currently is below:

while($row =& $result->fetchRow(DB_FETCHMODE_ASSOC))
{
	if($row['jm1_active_booking'] != null)
	{
		$count++;
		$sql2 = "select * from jms_02mast where jm2_booking_num = '".$row['jm1_active_booking']."'";
		$result2 = $myConn->query($sql2);
		while($row2 =& $result2->fetchRow(DB_FETCHMODE_ASSOC))
		{
			
			
			
			$diff    = abs(strtotime($currentDate) - strtotime($row2['jm2_book_date']));
			$days    = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
			
			if($days >1 && $days <6)
			{
				$OnetoFiveDays++;
			}
			if($days >5 && $days < 31)
			{
				$FivetoThirtyDays++;				
			}
			if($days > 30 && $days < 61)
			{
				$ThirtyOnetoSixtyDays++;
			}
			if($days > 60 && $days < 91)
			{
				$SixtyOnetoNintyDays++;
			}
			if($days > 90 && $days < 121)
			{
				$NintyOnetoOneTwentyDays++;
			}
			if($days >120 && $days < 181)
			{
				$OneTwentyOnetoOneEightyDays++;
			}
			if($days >180 && $days <366)
			{
				$OneEightyOnetoThreeSixtyFiveDays++;
			}
			if($days > 365)
			{
				$OverThreeSixtyFiveDays++;
			}
			if($days < 1)
			{
				$lessthanday++;
			}
	}

Open in new window


Currently it works fine when I print out the different variables.  My question is:

1) if $days does not match any of those conditions (Lets say I screw something up and want to be able to double check) I would like it to print the values that do not match anything

2) Is this a bad way to do this?  I know it WORKS, but it be better using an array, or something else I'm not thinking of? Or does it not really matter?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial