我试图在while循环中使用while循环之外的变量,但它在循环中工作并显示正确的日期。但是当使用outide循环时,它会显示错误的日期01/01/1970
。
如果有人能指出我的错误,我将不胜感激。非常感谢。
$Destdate = $_POST['box_rtv'];
$brtvarray = array();
$brtvarray = $Destdate;
$ddate = array();
foreach ($brtvarray as $destbox) {
$sql = "SELECT destroydate FROM act WHERE item = '".$destbox."'";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error($conn));
if (mysqli_num_rows($result) > 0) {
while ($row_code = mysqli_fetch_array($result)) {
$ddate[] = date('d/m/Y', strtotime($row_code['destroydate']));
}
}
}
$company = strtoupper(mysqli_real_escape_string($conn, $_POST['rtvcompany']));
$activity = "Box Retrieval";
$address = ucwords(mysqli_real_escape_string($conn, $_POST['address']));
$service = ucwords(mysqli_real_escape_string($conn, $_POST['service']));
$success = 'SUCCESS';
$authorised = ucwords(mysqli_real_escape_string($conn,$_SESSION['ls_name_usr']));
$dept = strtoupper(mysqli_real_escape_string($conn,$_POST['rtvdept']));
$boxitems = $_POST['box_rtv'];
$box = implode(",",$boxitems);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$outString .= "$box" . " ";
$sql = "INSERT INTO `act` (service, activity, department, company, address, `user`, `date`, destroydate, item, new) VALUES ('$service', '$activity', '$dept', '$company', '$address', '$authorised', NOW(), '".$ddate."', '$boxes', 1)";
$result = mysqli_query($conn, $sql) or die ('Error inserting box:' . mysqli_error($conn));
$sql = "UPDATE boxes SET status = 1 WHERE customer = '$company' AND custref = '$boxes'";
$result = mysqli_query($conn, $sql) or die ('Error updating box:' . mysqli_error($conn));
$sql = "UPDATE files SET boxstatus = 1 WHERE customer = '$company' AND boxref = '$boxes'";
$result = mysqli_query($conn, $sql) or die ('Error updating filebox:' . mysqli_error($conn));
}
$json = array($box);
$result = json_encode($json);
echo $result;
答案 0 :(得分:3)
如果你的目标是拥有日期数组,即$ ddate,那么这一行
$ddate = date('d/m/Y', strtotime($row_code['destroydate']));
应该是:
$ddate[] = date('d/m/Y', strtotime($row_code['destroydate']));
答案 1 :(得分:1)