Avatar of sittinDuck
sittinDuck asked on

Previous and next text buttons

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
PHPJavaScriptjQuery

Avatar of undefined
Last Comment
sittinDuck

8/22/2022 - Mon
Samuel Liew

Try this quick fix:
//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 id="weekSel" 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>';
										  // Add prev and next buttons
										  echo '<input type="button" value="Previous week" onclick="s=document.getElementById(\'weekSel\');try{s.selectedIndex=s.selectedIndex-1;}catch(e){}" />';
										  echo '<input type="button" value="Next week" onclick="s=document.getElementById(\'weekSel\');try{s.selectedIndex=s.selectedIndex+1;}catch(e){}" />';
										  if (isset($_GET['week'])) { echo ' <a href="tablebookings.php">Show current week</a>'; }
                                echo '<div class="clear">&nbsp;</div>';

Open in new window

ASKER
sittinDuck

Seems like it doesn't work. Can it be text buttons? :-)
Samuel Liew

Did you mean: Text Links or Buttons?

Anyway, if possible please include the page code, or a link to it.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
sittinDuck

Text links - sorry!

Page code attached :-)
ASKER
sittinDuck


<?php

//load files
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/datetime.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/session_start.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/Connections/db.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/restrictaccess.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/logout.php");

//page specific files
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/substr.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/functions/timeconvert.php");

//accesscheck
if ($row_access['tablebooking_view'] == 'N') {
	header('location: /dashboard.php'); exit; }


//lock for new reservations
if ( (isset($_GET['date'])) && ($_GET['lock'] == 'true') ) {

  mysql_select_db($database_db, $db);
  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".$_GET['date']."'";
  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
  $row_check_locked = mysql_fetch_assoc($check_locked);
  $totalRows_check_locked = mysql_num_rows($check_locked);	

if ($totalRows_check_locked == 0) {
	
	$mysql = mysql_query("INSERT INTO reservation_locks SET date = '".$_GET['date']."', locked_by = '".$_SESSION['MM_UserId']."'"); 
	
	// Activity
	$activity = mysql_query("INSERT INTO activity SET idid = '".$_SESSION['MM_UserId']."', type = 'tb_locked', time = '".$datetime."', 
	ip = '".$_SERVER['REMOTE_ADDR']."', var_1 = '".$_GET['date']."'") or die(mysql_error());
}
  $_SESSION['msg']['text'] = 'You have locked for new reservations to:<br />'.ucfirst(timeconvert_aar($_GET['date']));
  $_SESSION['msg']['type'] = 'info';
  session_write_close();
  header('location: /booking/tablebookings.php'); exit;
}

//open for new reservations
if ( (isset($_GET['date'])) && ($_GET['lock'] == 'false') ) {

  mysql_select_db($database_db, $db);
  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".$_GET['date']."'";
  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
  $row_check_locked = mysql_fetch_assoc($check_locked);
  $totalRows_check_locked = mysql_num_rows($check_locked);	

if ($totalRows_check_locked > 0) {
	$mysql = mysql_query("DELETE FROM reservation_locks WHERE `date` = '".$_GET['date']."'"); 
	
	// Activity
	$activity = mysql_query("INSERT INTO activity SET idid = '".$_SESSION['MM_UserId']."', type = 'tb_open', time = '".$datetime."', 
	ip = '".$_SERVER['REMOTE_ADDR']."', var_1 = '".$_GET['date']."'") or die(mysql_error());
}
  $_SESSION['msg']['text'] = 'You have opened for new reservations to:<br />'.ucfirst(timeconvert_aar($_GET['date']));
  $_SESSION['msg']['type'] = 'info';
  session_write_close();
  header('location: /booking/tablebookings.php'); exit;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Housekeeping - Karel van Mander</title>
<!-- Favicons --> 
<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/favicons.php'); ?>
<!-- Main Stylesheets --> 
<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/stylesheets.php'); ?>
<!-- JavaScripts --> 
<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/javascripts.php'); ?>
<script type="text/javascript">
$(document).ready(function(){
						   
	/* setup navigation, content boxes, etc... */
	Administry.setup();

});
</script>

</head>
<body>
	
      <!-- Header -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/pageheader.php'); ?>
	<!-- End of Header -->
	
	<!-- Page title -->
		<div id="pagetitle">
		<div class="wrapper">
			<h1>Booking &rarr; <span>Table reservations</span></h1>
			<!-- Quick search box -->
			<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/globalsearch.php'); ?>
		</div>
	</div>
	<!-- End of Page title -->
	
		<!-- Page content -->
		<div id="page">
		<!-- Wrapper -->
		<div class="wrapper">
				<!-- Left column/section -->
				<section class="column width8 first">
                	<h3>Table reservations</h3>
					<span class="subtitle">Table reservations overview</span>
					<hr>
                
                <?php

				//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>';
				
				
				if ($row_access['guestlist'] == 'Y') {
				//Create the Grid for the Guestlist.
				//set How Many Rows and columns
				$row_count = 0;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				   if($week == $get_week){
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }
						  
							echo '';
					  }
					  echo '';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									echo '<td align="center" style="background-color:#e2e9f3;"><strong>Guestlist /no tables</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']); $linkdate = date('d-m-Y', $days['Monday']); }
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); $linkdate = date('d-m-Y', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); $linkdate = date('d-m-Y', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); $linkdate = date('d-m-Y', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); $linkdate = date('d-m-Y', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); $linkdate = date('d-m-Y', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); $linkdate = date('d-m-Y', $days['Sunday']);  }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT id FROM reservations WHERE booking_date = '".$coldate."' AND table_nightclub_1 IS NULL";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									
									if ($totalRows_reservations > 0) { ?>
									<td align="center" class="booking"><a href="/booking/guestlist.php?date=<?php echo $coldate; ?>"><?php echo $totalRows_reservations; ?> groups</a></td>
                                    <?php } else { ?>
                                    <td align="center"><a href="/booking/guestlist.php?date=<?php echo $coldate; ?>"><?php echo $totalRows_reservations; ?> groups</a></td>
                  					<?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
							echo '<div class="clear">&nbsp;</div>'; }
				
				
				//Create the Grid for Nightclub.
				//set How Many Rows and columns
				$row_count = 9;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays']; 
				   if($week == $get_week){
					  echo '<tr><th><strong><font size="2">Nightclub</font></strong><br /><font size="-3"><a href="/img/plans/nightclub.png" class="nyroModal" title="Show nightclub overview">Show map</a></font></th>';
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }
						  
						  mysql_select_db($database_db, $db);
						  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".date('Y-m-d',$day)."'";
						  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
						  $row_check_locked = mysql_fetch_assoc($check_locked);
						  $totalRows_check_locked = mysql_num_rows($check_locked);
						  
						  if ($totalRows_check_locked > 0) { 
						  $locked_bgcolor = ' style="background-color:#f9c8c8;"'; $locked_img = 'lock_open.png';  $locked_link = 'false'; 
						  } else { 
						  $locked_bgcolor = ''; $locked_img = 'lock.png'; $locked_link = 'true'; }
						  
							echo '<th'.$locked_bgcolor.'><strong>' . $d_day . '</strong> <img src="/img/icons/printer.png" width="12" height="12" border="0" 
							onClick="window.location.href=\'print_tablebookings.php?date='.date('Y-m-d', $day).'\'" title="Print table reservations" /> 	
							<img src="/img/icons/script.png" width="12" height="12" border="0" onClick="window.location.href=\'print_guestlist.php?date='.date('Y-m-d', $day).'\'" 
							title="Print guestlist" /> <img src="/img/icons/'.$locked_img.'" width="12" height="12" onClick="window.location.href=\'tablebookings.php?date='.date('Y-m-d', $day).'&lock='.$locked_link.''.'\'" title="Lock/open for new reservations" /><br />' . date('Y-m-d',$day) . '</th>';
					  }
					  echo '</tr>';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									echo '<td align="center"><strong>Table ' . $table . '</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']); }
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT * FROM reservations WHERE booking_date = '".$coldate."' AND table_nightclub_".$table." = 'Y' LIMIT 1";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									if ($totalRows_reservations > 0) { ?>
									<td class="booking"><a href="tablebooking.php?id=<?php echo $row_reservations['id']; ?>" title="<?php echo htmlspecialchars($row_reservations['customer_name']); ?>"><?php echo htmlspecialchars(abbreviate($row_reservations['customer_name'], 17)); ?></a></td>
									<?php } else { ?> 
									<td onClick="document.location.href='create_tablebooking.php?date=<?php echo $coldate; ?>&table=<?php echo $table; ?>'" class="nobooking">New reservation</td>
                                    <?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
							echo '<div class="clear">&nbsp;</div>';
				
				
				//Create the Grid for Lounge.
				//set How Many Rows and columns
				$row_count = 5;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				   if($week == $get_week){
					  echo '<tr><th><strong><font size="2">Lounge</font></strong><br /><font size="-3"><a href="/img/plans/lounge.png" class="nyroModal" title="Show lounge overview">Show map</a></font></th>';
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }

						  mysql_select_db($database_db, $db);
						  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".date('Y-m-d',$day)."'";
						  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
						  $row_check_locked = mysql_fetch_assoc($check_locked);
						  $totalRows_check_locked = mysql_num_rows($check_locked);
						  
						  if ($totalRows_check_locked > 0) { 
						  $locked_bgcolor = ' style="background-color:#f9c8c8;"'; $locked_img = 'lock_open.png';  $locked_link = 'false'; 
						  } else { 
						  $locked_bgcolor = ''; $locked_img = 'lock.png'; $locked_link = 'true'; }
						  
							echo '<th'.$locked_bgcolor.'><strong>' . $d_day . '</strong> <img src="/img/icons/printer.png" width="12" height="12" border="0" 
							onClick="window.location.href=\'print_tablebookings.php?date='.date('Y-m-d', $day).'\'" title="Print table reservations" /> 	
							<img src="/img/icons/script.png" width="12" height="12" border="0" onClick="window.location.href=\'print_guestlist.php?date='.date('Y-m-d', $day).'\'" 
							title="Print guestlist" /> <img src="/img/icons/'.$locked_img.'" width="12" height="12" onClick="window.location.href=\'tablebookings.php?date='.date('Y-m-d', $day).'&lock='.$locked_link.''.'\'" title="Lock/open for new reservations" /><br />' . date('Y-m-d',$day) . '</th>';
							
					  }
					  echo '</tr>';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									$table_pointer = $i+11;
									echo '<td align="center"><strong>Table ' . $table_pointer . '</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']);}
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT * FROM reservations WHERE booking_date = '".$coldate."' AND table_lounge_".$table." = 'Y' LIMIT 1";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									if ($totalRows_reservations > 0) { ?>
									<td class="booking"><a href="tablebooking.php?id=<?php echo $row_reservations['id']; ?>" title="<?php echo htmlspecialchars($row_reservations['customer_name']); ?>"><?php echo htmlspecialchars(abbreviate($row_reservations['customer_name'], 17)); ?></a></td>
									<?php } else { ?> 
									<td onClick="document.location.href='create_tablebooking.php?date=<?php echo $coldate; ?>&table=<?php echo $table_pointer; ?>'" class="nobooking">New reservation</td>
                                    <?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
				echo '<div class="clear">&nbsp;</div>';
				
				
				//Create the Grid for Patio.
				//set How Many Rows and columns
				$row_count = 4;
				$column_count = 8;
				echo '<table class="weekview">';
				
				foreach($weeks as $week_data){
				  $week  = $week_data['weeks'];
				  $days = $week_data['weekdays'];
				   if($week == $get_week){
					  echo '<tr><th><strong><font size="2">Terrace</font></strong><br /><font size="-3"><a href="/img/plans/patio.png" class="nyroModal" title="Show terrace overview">Show map</a></font></th>';
					  foreach($days as $day){
						  
						  switch(date('N', $day)){
   						  case 1:$d_day = "Monday";break;
    					  case 2:$d_day = "Tuesday";break;
    					  case 3:$d_day = "Wednesday";break;
    					  case 4:$d_day = "Thursday";break;
    					  case 5:$d_day = "Friday";break;
    					  case 6:$d_day = "Saturday";break;
    					  case 7:$d_day = "Sunday";break;
						  }

						  
						  mysql_select_db($database_db, $db);
						  $query_check_locked = "SELECT id FROM reservation_locks WHERE `date` = '".date('Y-m-d',$day)."'";
						  $check_locked = mysql_query($query_check_locked, $db) or die(mysql_error());
						  $row_check_locked = mysql_fetch_assoc($check_locked);
						  $totalRows_check_locked = mysql_num_rows($check_locked);
						  
						  if ($totalRows_check_locked > 0) { 
						  $locked_bgcolor = ' style="background-color:#f9c8c8;"'; $locked_img = 'lock_open.png';  $locked_link = 'false'; 
						  } else { 
						  $locked_bgcolor = ''; $locked_img = 'lock.png'; $locked_link = 'true'; }
						  
							echo '<th'.$locked_bgcolor.'><strong>' . $d_day . '</strong> <img src="/img/icons/printer.png" width="12" height="12" border="0" 
							onClick="window.location.href=\'print_tablebookings.php?date='.date('Y-m-d', $day).'\'" title="Print table reservations" /> 	
							<img src="/img/icons/script.png" width="12" height="12" border="0" onClick="window.location.href=\'print_guestlist.php?date='.date('Y-m-d', $day).'\'" 
							title="Print guestlist" /> <img src="/img/icons/'.$locked_img.'" width="12" height="12" onClick="window.location.href=\'tablebookings.php?date='.date('Y-m-d', $day).'&lock='.$locked_link.''.'\'" title="Lock/open for new reservations" /><br />' . date('Y-m-d',$day) . '</th>';
							
					  }
					  echo '</tr>';
				
					   for($i = 0; $i <= $row_count; $i += 1){
						   echo '<tr>';
						   for($j = 1;$j <= $column_count; $j += 1){
							   if($j == 1){
								   	$table = $i+1;
									if ($table == 1) { $abc = 'A'; 
									} else if ($table == 2) { $abc = 'B'; 
									} else if ($table == 3) { $abc = 'C';
									} else if ($table == 4) { $abc = 'D';
									} else if ($table == 5) { $abc = 'E'; }
									echo '<td align="center"><strong>Table ' . $abc . '</strong></td>';
							   }else{
								   
								   	if ($j == 2) { $coldate = date('Y-m-d', $days['Monday']); $linkdate = date('d-m-Y', $days['Monday']); }
									if ($j == 3) { $coldate = date('Y-m-d', $days['Tuesday']); $linkdate = date('d-m-Y', $days['Tuesday']); } 
									if ($j == 4) { $coldate = date('Y-m-d', $days['Wednesday']); $linkdate = date('d-m-Y', $days['Wednesday']); } 
									if ($j == 5) { $coldate = date('Y-m-d', $days['Thursday']); $linkdate = date('d-m-Y', $days['Thursday']); } 
									if ($j == 6) { $coldate = date('Y-m-d', $days['Friday']); $linkdate = date('d-m-Y', $days['Friday']); } 
									if ($j == 7) { $coldate = date('Y-m-d', $days['Saturday']); $linkdate = date('d-m-Y', $days['Saturday']); }
									if ($j == 8) { $coldate = date('Y-m-d', $days['Sunday']); $linkdate = date('d-m-Y', $days['Sunday']);  }
									
									mysql_select_db($database_db, $db);
									$query_reservations = "SELECT * FROM reservations WHERE booking_date = '".$coldate."' AND table_patio_".$table." = 'Y' LIMIT 1";
									$reservations = mysql_query($query_reservations, $db) or die(mysql_error());
									$row_reservations = mysql_fetch_assoc($reservations);
									$totalRows_reservations = mysql_num_rows($reservations);
									
									if ($totalRows_reservations > 0) { ?>
									<td class="booking"><a href="tablebooking.php?id=<?php echo $row_reservations['id']; ?>" title="<?php echo htmlspecialchars($row_reservations['customer_name']); ?>"><?php echo htmlspecialchars(abbreviate($row_reservations['customer_name'], 17)); ?></a></td>
									<?php } else { ?> 
									<td onClick="document.location.href='create_tablebooking.php?date=<?php echo $linkdate; ?>&table=<?php echo $abc; ?>'" class="nobooking">New reservation</td>
                                    <?php
									}
							   }
						   }
						   echo '</tr>';
					   }
				   }
				}
				
				echo '</table>';
				
				echo '<div class="clear">&nbsp;</div>';
				
				//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>'; }

				?>

                <div class="clear">&nbsp;</div>

				</section>
				<!-- End of Left column/section -->
				
		</div>
		<!-- End of Wrapper -->
	</div>
	<!-- End of Page content -->
	
	<!-- Page footer -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/pagefooter.php'); ?>
	<!-- End of Page footer -->
	
	<!-- Animated footer -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/animatedfooter.php'); ?>
	<!-- End of Animated footer -->
	
	<!-- Scroll to top link -->
	<?php include_once($_SERVER["DOCUMENT_ROOT"] . '/includes/scroll.php'); ?>
    
    <!-- Javascript load -->
	<script type="text/javascript" src="/js/administry.js"></script>
	</body>
	</html>
	<?php
	mysql_free_result($reservations);
	mysql_free_result($check_locked);
	?>

Open in new window

Samuel Liew

1) You need to add an id="weekSel" to the select:

//Create the Drop down for the weeks
echo 'Select week: <select id="weekSel" onchange="window.location=\'?week=\' + (this.value);">';

2) The links will refer to the select with that id:

// Add prev and next links
echo '<a href="javascript:s=document.getElementById(\'weekSel\'); s.selectedIndex=s.selectedIndex-1; return false;">Previous week</a>';
echo '<a href="javascript:s=document.getElementById(\'weekSel\'); s.selectedIndex=s.selectedIndex+1; return false;">Next week</a>';

Test page attached:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Increment/Decrement Selected Option</title>
</head>

<body>
<select id="mySelect">
	<option>a</option>
	<option>b</option>
	<option>c</option>
	<option>d</option>
	<option>e</option>
</select>
<a href="javascript:s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex-1; return false;">Previous</a> 
<a href="javascript:s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex+1; return false;">Next</a>
</body>
</html>

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
sittinDuck

Thank you Sam. I'm using Firefox and in this browser it won't work. However, if I try in Safari, it does work.

Is there a fix for this? ;-)

Samuel Liew


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Increment/Decrement Selected Option</title>
</head>

<body>
<select id="mySelect">
        <option>a</option>
        <option>b</option>
        <option>c</option>
        <option>d</option>
        <option>e</option>
</select>
<a href="#" onclick="s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex-1;">Previous</a> 
<a href="#" onclick="s=document.getElementById('mySelect'); s.selectedIndex=s.selectedIndex+1;">Next</a>
</body>
</html>

Open in new window

ASKER
sittinDuck

Thanks!

It's now changing the option in the dropdown but it doesn't reload the page with the new settings.

As you can see I'm using the dropdown to select a week :-) Is there a way to activate the onchange?

<select id="weekSel" onchange="window.location=\'?week=\' + (this.value);">
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Samuel Liew

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
sittinDuck

Thank you, it works now!

Is it possible to include the page name in the value? Like..

window.location = 'tablebookings.php?week='.document.getElementById('weekSel').value; ?
Samuel Liew

yes, why not? but to concatentate string, you use the "+" operator instead of a "."
ASKER
sittinDuck

Thanks!!! :-)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.