以M d,Y格式转换日期会导致其他行中的显示日期 [英] Converting Date in M d, Y format leads to display date in other rows
问题描述
我们正在获取列到期日期 &中的值在网站中显示。
We are fetching values of column "due_date" & displaying in site.
以下代码的帮助。
$i = 0;
foreach($order as $orderData)
{
$k = 0;
while ($k < count($orderitemsarray)) {
if ($orderitemsarray[$k] != '0') {
if($accountType == "admin") {
$due_date='';
while($datas = $stmt1->fetch()) {
$due_date=$datas['due_date'];
$oDate1 = new DateTime($datas['due_date']);
$sDate1 = $oDate1->format("M d, Y");
}
$responce[] = array( $due_date );
}
return json_encode($responce);
脚本
var colsOption = [
{id: 'due_date' , header: " Due Date" , width :"140"},
];
我想以以下格式显示日期:
I want to display date in this format :
所以我尝试了以下代码
$responce[] = array(
$sDate1
);
现在其他行也显示日期,但其他行没有没有值数据库中的[截止日期]。
Now its displaying Date for other rows also, but for those other rows there is no values [ Due date ] in Database.
推荐答案
在您的代码中,您正在使用循环在$ response []中添加值。发生的是$ sDate1的值未初始化为null。因此,当它是第一次设置时,它不会更改,直到下一个Due_date值出现,因此它将继续重复最后的$ sDate1值来解决此问题,请转到此文件中的第152行 http://pastebin.com/PnPnX9Wiand 会初始化$ sDate1。
In your code you your are adding values in $response[] using loop. What happens is that value of $sDate1 is not initialized to null. So when it is set for first time it does not change until next due_date value comes so it keeps on repeating last $sDate1 value to solve this , Go to line 152 in this file http://pastebin.com/PnPnX9Wiand bellow it initialize $sDate1. Make changes in this code.
$paid_status='';
$delivery_status='';
$due_date='';
添加$ sDate1 =’’;。
Add $sDate1='';. It will look like this.
$paid_status='';
$delivery_status='';
$due_date='';
$sDate1='';
现在更改此代码。
$due_date=$datas['due_date'];
$oDate1 = new DateTime($datas['due_date']);
$sDate1 = $oDate1->format("M d, Y");
具有此代码。
$oDate1 = new DateTime($datas['due_date']);
$due_date = $oDate1->format("M d, Y");
$sDate1 = $oDate1->format("M d, Y");
这篇关于以M d,Y格式转换日期会导致其他行中的显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!