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?
 
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
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.