Jump to content

Dates do not POST right- I think


hkalan2007

Recommended Posts

Hello Everyone,

 

I seem to be going no place fast...

 

In a PHP file, I should be taking a date from a jquery datpicker, and get it to a format that mysql will read in the yy-mm-dd format with...

 

if(isset($_POST['choice']))
$choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d");

 

Can't seem to get a single inline(embeded) jquery Datepicker date to post right to the PHP and mysql correctly to return data from the table.. My reading has me to understand it should be right, but it is not. Now the datepicker select does have several POST events to PHP that trigger from the single select... data being requsted in PHP by the day, month, and year as well as PHP to use the date to create a highcharts graph in the PHP file to select data for hours of a day, days of a month, and months of a year.

 

The Table is very simple... date, time, power

 

Here is the PHP for dayPower.php that will just collect the sum data for the selected day in the datepicker...

 

<?
if(isset($_POST['choice']))
$choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d");
$con = mysql_connect("localhost","root","mackie1604"); 
if (!$con)  { 
die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("inverters", $con); 

$sql = 'SELECT sum(power) AS power '        
.'FROM feed '       
.'WHERE date = $choice';
$res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error());
$row = mysql_fetch_assoc($res);
echo $row['power']; 
?>

 

Here is the javascript that sends the date and how it post the PHP file.

 

$(document).ready(function () {   
      $('#datepicker').datepicker({onSelect: function(dateText,inst) {
            var myDate = $(this).datepicker('getDate');
            $('#apDiv1').html($.datepicker.formatDate('DD, d', myDate));
            $('#apDiv5').html($.datepicker.formatDate('MM', myDate));
            $('#apDiv7').html($.datepicker.formatDate('yy', myDate));
            $.post('dayPower.php', {choice: inst.val()}, function(data) {
                $('#apDiv2').html(data).show();
            });
            $.post('dayGraph.php', {choice: inst.val()}, function(data) {
                  $('#apDiv4').html().show();
		});
		$.post('monthPower.php', {choice: inst.val()}, function(data) {
                $('#apDiv6').html(data).show();
            });
            $.post('monthGraph', {choice: inst.val()}, function(data) {
                  $('#apDiv9').html().show();
		});
		$.post('yearPower.php', {choice: inst.val()}, function(data) {
                $('#apDiv8').html(data).show();
            });
            $.post('yearGraph', {choice: inst.val()}, function(data) {
                  $('#apDiv10').html().show();
		});
      }});
});

 

What am I doing wrong

 

Alan

 

 

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.