PHP - Switch statement

I have 8 columns in my table. The first 4 display data from the table. The last 4 columns display the data of the next for dates as column headers. This part works. What i want under each of the 4 data is the status of the work. So if it is between this data and the next date todays status is xxxxx, if tomorrows data is between is and that then tomorrows status is xxx and so on for 4 days.

I am just having issues with figuring out the logic logic....I have added the switch statement but it is more the logic that the correct way of putting it...

I have attached the file...
index.php
j8547Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
You need to clarify what it is you are trying to do.  In your code I see references to "moving targets" - ex:
 $date_format = 'd/m/y';
 $today = strtotime('now');
 $tomorrow = strtotime('+1 day', $today);
 $nextday = strtotime('+2 day', $today);
 $nextday1 = strtotime('+3 day', $today);

Open in new window


Let's say today is actually "February 1, 2018".  So, when I visit the site on "February 1, 2018", then $today will be "February 1, 2018", so I expect to see the status for "February 1, 2018".  However, on the next day, $today will be "February 2, 2018". Does that mean the status for "February 1, 2018" is useless?  Or did you intend to initialize $today from a date in your database?
0
j8547Author Commented:
Correct it is a moving date. So you will always see the status from today for the next 4 days. The status is calculated from dates in the database. So if today is in between 2 dates then that is the status. Do I make sense or am i confusing things?

Joanne
0
j8547Author Commented:
So I have the logic of the Switch working for 'Today' so I can just replicate for the other days. I just need the format of the date in the switch to be the same as the one from the table. Anything i try is error out....I have attached updated code with working Switch statement.
index.php
0
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

hieloCommented:
>> the format of the date in the switch to be the same as the one from the table
try:
  $date_format = 'd/m/y';
  $today = date($date_format, strtotime('now') );
  $tomorrow = date($date_format, strtotime('+1 day', $today) );
  $nextday = date($date_format, strtotime('+2 day', $today) );
  $nextday1 = date($date_format, strtotime('+3 day', $today) );

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
j8547Author Commented:
I was able to figure out the date but it seems my Select is not working as i thought..... Is this the correct syntax..It is giving me the first one even though that is not true...

Switch ($today)
                  {
                   Case $today >= $Sdate and $today < Pdate:
                        $statusToday = "Admin Stage";
                        break;
                   Case $today >= $Pdate and $today <$Tdate:
                         $statusToday = "Prod Stage";
                         break;
0
j8547Author Commented:
Got it working. thanks
0
hieloCommented:
>> Case $today >= $Sdate && $today < Pdate:
That evaluates to a boolean (true or false), so strictly speaking your switch should be:
switch( true ){ ...}

Also, Case $Today >= $Tdate && $today <$Shdate: should be lowercase $today.

	switch (true)
			{
	 		case ($today >= $Sdate && $today < $Pdate):
				$statusToday = "Admin Stage";
				break;
	 		case ($today >= $Pdate && $today <$Tdate):
	 			$statusToday = "Prod Stage";
	 			break;
	 		case ($today >= $Tdate && $today <$Shdate):
	 			$statusToday = "Third Stage";
	 			break;
			case ($today >= $Shdate):
	 			$statusToday = "Shipped";
	 			break;
	 		default:
			    $statusToday = "Complete";
        		break;
		}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.