We help IT Professionals succeed at work.
Get Started

Previous and next text buttons

sittinDuck
sittinDuck asked
on
454 Views
Last Modified: 2012-05-10
Hello experts,

Please look at the attached code and screenshot. I want to add two buttons; "Previous week" and "Next week" beside of the dropdown list.

I hope someone can help me implement this :-)

Thanks in advance!
//Get First Day of year;
				$year = date('Y');
				
				$get_week = (isset($_GET['week'])) ? urldecode($_GET['week']) : date('W')." ({$year})";
				$get_week = 'Week ' . $get_week;
				
				$yearBeginDate = strtotime("{$year}-01-01");
				$yearVal = intval(date('Y') + 1);
				$yearEndDate = strtotime("{$yearVal}-06-01");
				
				$currentDate = $yearBeginDate;
				
				//Get the Day of the Week Jan 1st is on
				$janFirstDay = date('N',$currentDate) - 1;
				$currentDate = $currentDate - (86400 * $janFirstDay);
				
				//Get the Last Day of the year to finish the week
				$DecLastDay = date('N',$yearEndDate) - 1;
				$yearEndDate = $yearEndDate + (86400 * $DecLastDay);
				
				$weekDays = array();
				while($currentDate < $yearEndDate){
					$weekDays[date('l',$currentDate)] = $currentDate;
					if(date('N',$currentDate) == 7){
						$weeks[] = array('weeks' => 'Week ' . date('W (Y)',$currentDate), 'weekdays' => $weekDays);
						$weekDays = array();
					}
					$currentDate += 86400;
				}

//Create the Drop down for the weeks
				echo 'Select week: <select onchange="window.location=\'?week=\' + (this.value);">';
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				  $firstWeekDay = reset($days);
					$lastWeekDay = end($days);
					$option = '<option ';
					$option .= ($week == $get_week) ? ' selected="selected" ' : '';
					$option .= ' value="' . urlencode(substr($week, 5)) . '">' . $week . ': ' . date('Y-m-d',$firstWeekDay) . ' - ' . date('Y-m-d',$lastWeekDay) . '</option>';
					echo $option;
				}
				echo '</select>'; if (isset($_GET['week'])) { echo ' <a href="tablebookings.php">Show current week</a>'; }
				echo '<div class="clear">&nbsp;</div>';

Open in new window

tb.jpg
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE