Jump to content

Calendar paging


AJM2
Go to solution Solved by mac_gyver,

Recommended Posts

I am not sure I am doing this correctly. My goal is to have a button on each side of the page with today's date in the middle as dropdown lists allowing to page through dates (see image) or pick a specific date. I have the code somewhat of working. It will page up tomorrow, next day, next day... and it goes down, yesterday, day before... when starting at today.

But once I go either up or down I can't page back in the opposite direction. The ultimate goal is to pass the "current" date into a query to get today's data as you page through. I hope I described this well enough. I don't want to use a date picker where a calendar pops up. Any pointers would be appreciated.

<html>
	<head>
		<title></title>
	</head>
	<body>
				<form action="calendar_form.php" method="post" name="f1">
				<?php 
				error_reporting(E_ALL);
				ini_set('display_errors', '1');
				// Default dates
					$beginYesterday = date('Y-m-d H:i:s',strtotime('yesterday'));
					$beginOfDay = date('Y-m-d H:i:s',strtotime('today'));
					$endOfDay = date('Y-m-d H:i:s',strtotime('tomorrow'));

					$tomorrow = date('Y-m-d H:i:s', strtotime($beginOfDay . '+1 days'));
					$f_today = date('m-d-Y', strtotime('today midnight'));
					$yesterday = date('Y-m-d H:i:s', strtotime('-1 days'));
					
				// Check the form was submitted
				if ($_SERVER['REQUEST_METHOD'] == 'POST') {
					$yesterday = $_POST['yesterday'];
					$tomorrow = $_POST['tomorrow'];
					
					if($_POST['Submit'] == 'Tomorrow'){
						
						$tomorrow = date('Y-m-d H:i:s', strtotime($tomorrow . '+1 days'));
						$today = date('m-d-Y', strtotime($_POST['tomorrow']));
						$yesterday = date('Y-m-d H:i:s', strtotime($tomorrow . '-1 days'));
						$f_today = $today;
					}
					elseif($_POST['Submit'] == 'Yesterday'){
						
						$tomorrow = date('Y-m-d H:i:s', strtotime($yesterday . '+1 days'));
						$today = date('m-d-Y', strtotime($_POST['yesterday']));
						$yesterday = date('Y-m-d H:i:s', strtotime($yesterday . '-1 days'));
						$f_today = $today;
					}
				}
					
				?>
				<table border="1" align="center" width="100%">
						<input type="hidden" name="yesterday" value=<?php echo $yesterday;?>>
						<input type="hidden" name="tomorrow" value=<?php echo $tomorrow;?>>
						<tr>
							<td align="center" width="20%"><?php echo $yesterday;?><input type="Submit" name="Submit" value="Yesterday"></td>
							<td align="center" width="60%"> <?php echo $f_today;?></td>
							<td align="center" width="20%"><input type="Submit" name="Submit" value="Tomorrow"><?php echo $tomorrow;?></td>
						</tr>
                 <?php 						
						if ($_SERVER['REQUEST_METHOD'] == 'POST') {
						
						//<!---  Form view  --->						
						echo"<tr><td>query</td></tr>";
						}
						else{
						//<!---  Default view   --->
						"<tr><td>default</td></tr>";
						}
			?>			
			
				</table>		
				</form>
				

	</body>
</html>




 

wucalendar.png

Link to comment
Share on other sites

  • Solution

the operation is to simply either add one day or subtract one day from the current date -

<html>
	<head>
		<title></title>
	</head>
	<body>
		<form method="post" name="f1">
		<?php
		error_reporting(E_ALL);
		ini_set('display_errors', '1');
		// Default dates
		$today = date('Y-m-d H:i:s',strtotime('today'));

		// Check the form was submitted
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			$today = $_POST['today'];
			if($_POST['Submit'] == 'Tomorrow'){
				$today = date('Y-m-d H:i:s', strtotime($today . '+1 days'));
			}
			if($_POST['Submit'] == 'Yesterday'){
				$today = date('Y-m-d H:i:s', strtotime($today . '-1 days'));
			}
		}
		?>
		<table border="1" align="center" width="100%">
			<input type="hidden" name="today" value=<?php echo $today;?>>
			<tr>
				<td align="center" width="20%"><input type="Submit" name="Submit" value="Yesterday"></td>
				<td align="center" width="60%"> <?php echo $today;?></td>
				<td align="center" width="20%"><input type="Submit" name="Submit" value="Tomorrow"></td>
			</tr>
		 <?php
			if ($_SERVER['REQUEST_METHOD'] == 'POST') {

			//<!---  Form view  --->
			echo"<tr><td>query</td></tr>";
			}
			else{
			//<!---  Default view   --->
			"<tr><td>default</td></tr>";
			}
		?>
		</table>
		</form>
	</body>
</html>

 

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.