jquery - How to reformat dates in m/d/y with in PHP array from jqgrid post data? -
i have jqgrid sends update post data php processing database. right have problem converting 3 of columns desired yyyy-mm-dd format injecting mysql database. how convert data in array m/d/y mysql yyyy-mm-dd?where heck convert correctly data processed correctly , sent database? please need suggestions?
jqgrid colmodel code:
{name:'lastvisit', index:'lastvisit', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/d/yy',editable:true, edittype: 'text',mtype:'post' , editoptions:{size:10, datainit:function(elem){$(elem).datepicker({dateformat:'m/d/yy'});}}} , {name:'cdate', index:'cdate', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/d/yy', edittype: 'text',editable:true ,mtype:'post' ,editoptions:{size:10, datainit:function(elem){$(elem).datepicker({dateformat:'m/d/yy'});}}} , {name:'ddate', index:'ddate', width:70, align:'right',formatter: 'date',srcformat:'yyyy-mm-dd',newformat: 'm/d/yy',date:'true',editable:true, edittype: 'text',editoptions:{size:10, datainit:function(elem){$(elem).datepicker({dateformat:'m/d/yy'});}}} ,
here php code:
/* columns array format: $_post['variable'] => 'db column name' */ $crudcolumns = array( 'id'=>'id' ,'name'=>'name' ,'id_continent'=>'id_continent' ,'lastvisit'=>'lastvisit' ,'cdate'=>'cdate' ,'ddate'=>'ddate' );
then cleaned , readied processing:
/*----====|| , clean post variables ||====----*/ foreach ($postconfig $key => $value){ if(isset($_request[$value])){ $postconfig[$key] = fncleaninputvar($_request[$value]); } } foreach ($crudcolumns $key => $value){ if(isset($_request[$key])){ $crudcolumnvalues[$key] = '"'.fncleaninputvar($_request[$key]).'"'; } }
databse connect sent database update row:
case $crudconfig['update']: /* ----====|| action = update ||====----*/ if($debugmode == 1){$firephp->info('update','action');} $sql = 'update '.$crudtablename.' set '; /* create of update statements */ foreach($crudcolumns $key => $value){ $updatearray[$key] = $value.'='.$crudcolumnvalues[$key]; }; $sql .= implode(',',$updatearray); /* add additonal update statements here */ $sql .= ' id = '.$crudcolumnvalues['id']; if($debugmode == 1){$firephp->info($sql,'query');} mysql_query( $sql ) or die($firephp->error('couldn t execute query.'.mysql_error())); break;
i may not have understood question, if you're asking how convert 1 date format another...
$bad_date = '5/16/2013'; $good_date = date('y-m-d', strtotime($bad_date)); // returns 2013-05-16
... , change foreach ($crudcolumns)
code ...
foreach ($crudcolumns $key => $value){ if(isset($_request[$key])){ if ($key == 'lastvisit' || $key == 'cdate' || $key == 'ddate') { $crudcolumnvalues[$key] = '"'.date('y-m-d', strtotime($_request[$key])).'"'; } else { $crudcolumnvalues[$key] = '"'.fncleaninputvar($_request[$key]).'"'; } } }
Comments
Post a Comment