Get value from db when substracting 1 day from given date into user field

Hello =)

Been searching all over for a explaination for this, but can`t seem to get my head straight for what and how to do it.
Thing is, i have a form, where the user inserts a date, then the jquery “reloads” the page to get value 1 day before that given date user inputs. And then comes the question…
If there is no input the day before that date, how can i then display the value from the last given date before that date user inserts ?

ex.

2014-01-01 value: 345
2014-01-02 value: 3422

And user types 2014-01-04

2014-01-03 have no value, so it should dislay the value for day before that again, 2014-01-02 instead.

Anyone could help me with this ?
Thanks alot :slight_smile:

Kim

I really don’t know what you mean by jQuery “reloads”, because usually you use JQuery so you don’t have the page reloading:

Example:
Here the jQuery script ->

[code]$(function() {
/* The Countdown Timer to call the Ajax Method */
var updateTime = setInterval(displayTime, 1000);

/* The Ajax Method of Getting Time */
function displayTime() {
	var $clock = $('.clock');
	
		$.ajax({ // Start of ajax:
			url: 'sendCountDown.02.php',   // Pulling time from the server:         
			dataType: "json", // Format type:
			success: function(info) { // Grab the data from php and then display it:
				
				// Variables * Self-Explanatory *
				var days       =  info.countDown.days, // Grab total days till expiration:
						hours      =  info.countDown.h, // Grab total hours till expiration:
				    minutes    =  info.countDown.i, // Grab total mins till expiration:
						seconds    =  info.countDown.s, // Grab total secs till expiration:
						$msg       =  ''; 
													
						if (hours < 10) {
							hours = '0' + hours;
						}
						
						if (minutes < 10) {
							minutes = '0' + minutes;
						}
						
						if (seconds < 10) {
							seconds = '0' + seconds;	
						}
						
						$msg =  days + ' Days '  + hours + ' Hours ' + 				
						 minutes + ' Minutes ' + seconds + ' Seconds';
						
						/* Display Time in Message */				 
						$clock.text($msg);										
						
					},
					error: function (response) {
						var r = jQuery.parseJSON(response.responseText);
							alert("Message: " + r.Message);
							alert("StackTrace: " + r.StackTrace);
							alert("ExceptionType: " + r.ExceptionType);
						}
					}); // End of ajax call:
					
} // End of Function:	

}); // END OF DOC READY:[/code]

An here’s the PHP script->
[php]<?php
date_default_timezone_set(‘America/Detroit’); // Set the Default Time Zone:

session_start();

$future = (isset($_SESSION[‘future’])) ? $_SESSION[‘future’] : ‘2014-07-04 00:00:00’;

$expired = new DateTime($future);
$now = new DateTime();

$e[‘countDown’] = $now->diff($expired, true);

print json_encode($e); // JSON

[/php]

The jQuery manipulates the date that is sent via the server (PHP), not the other way around.

Sponsor our Newsletter | Privacy Policy | Terms of Service