我有一个while循环,其中包含一个引用另一个文件的数组:legProductionAllRecords.php。该文件返回一个数组,然后在循环中使用。我希望能够在我的javascript tableObj中使用$ orderArray,如图所示,但它不起作用。当我在$ inProgressArray中没有结果时显示没有结果。我还需要能够在此循环之外使用$ inProgressArray。
的index.php
$madeAt = 2;
$inProgressQuery ="SELECT * FROM leg_prod_inprogress WHERE madeat=".$madeAt;
$inProgressResult = mysql_query($inProgressQuery);
$orderArray = array();
$inProgressArray = array();
while($inProgressArray = mysql_fetch_array($inProgressResult,MYSQL_ASSOC)) {
$inPogressOrder = "-1";
if ($inProgressArray != false) {
$inPogressOrderNo = $inProgressArray['purchase_no'];
} else {
$inPogressOrderNo = -1;
}
require_once('legProductionAllRecords.php');
$allArray = legProductionAllRecords($madeAt, $inPogressOrderNo);
$orderArray = $allArray['allOrder'];
$inPogressOrder = $allArray['inprocessOrder'];
$toadyFinishedOrder = $allArray['todayFinishedOrder'];
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
var tableObj = {
data: <?php echo json_encode($orderArray); ?>,
processingData:<?php
if(!empty($inPogressOrder)&&$inPogressOrder!=''){
echo json_encode($inPogressOrder);
}
else{echo -1;} ?>,
}
</script>
</head>
</html>
legProductionAllRecords.php
<?php
function legProductionAllRecords($madeAt,$inPogressOrderNo){
$dayquery = "SELECT * FROM manufacturedat WHERE ManufacturedAtID=".$madeAt;//$madeAt is either 2 or 1
$dayresult = mysql_query($dayquery);
$dayArray = mysql_fetch_array($dayresult,MYSQL_ASSOC);
$day = $dayArray['LegCompletionNoItems'].' days';
$qry = "SELECT a.PURCHASE_No, a.legstyle, a.legfinish, a.LegQty, a.legheight, ".
"a.addlegstyle, a.addlegfinish, a.AddLegQty, a.ORDER_NUMBER, a.specialinstructionslegs, ".
"b.surname, b.first ".
"FROM purchase AS a LEFT JOIN contact AS b ON a.contact_no=b.CONTACT_NO ".
"WHERE a.legrequired='y' ".
"AND a.completedorders = 'n' ".
"AND a.quote = 'n' ".
"AND a.orderonhold = 'n' ".
"AND a.contact_no <> 326314 ".
"AND a.contact_no <> 324273 ".
"AND a.contact_no <> 313820 ".
"AND a.ORDER_DATE >= '2015-12-31' ".
"AND (a.cancelled IS NULL OR a.cancelled <> 'y') ";
$result = mysql_query($qry);
$orderArray = array();
$returnArray['inprocessOrder'] = null;
$returnArray['todayFinishedOrder'] = null;
while ($temp = mysql_fetch_array($result,MYSQL_ASSOC)){
if(!empty($temp)){
$temp['surname'] = mb_convert_encoding($temp['surname'],"UTF-8");
//$temp['title'] = mb_convert_encoding($temp['title'],"UTF-8");
$temp['first'] = mb_convert_encoding($temp['first'],"UTF-8");
$qcQuery = "SELECT * FROM qc_history WHERE ComponentID=7 AND Purchase_No=".$temp['PURCHASE_No']." ORDER BY QC_Date DESC";
$qcresult = mysql_query($qcQuery);
$temp2 = mysql_fetch_array($qcresult,MYSQL_ASSOC);
if($temp2['QC_StatusID']== 20 && $temp2['MadeAt']==$madeAt ){//$temp2['QC_StatusID']== 20 &&
//=====================Change the date format to week:day===============================//
$temp2['formatedBCWExpected'] = date('d/m/Y',strtotime($day,strtotime($temp2['BCWExpected'])));
$tep_time = date_sub(date_create($temp2['BCWExpected']),date_interval_create_from_date_string($day));
$time = explode(':',date_format($tep_time,'W:w'));
$week = (int)$time[0];
$weekday = (int)$time[1];
if($weekday == 0){
$weekday = 5;
}
if($weekday == 6){
$weekday = 5;
}
$temp2['WDdate'] = $week.':'.$weekday;
//=======================End of Change the date format to week:day===============================//
$temp['qc_history'] = $temp2;
$temp['cname'] = $temp['first'].' '.$temp['surname'];
if($temp['PURCHASE_No'] == $inPogressOrderNo){
$returnArray['inprocessOrder'] = $temp;
}
else{
array_push($orderArray, $temp);
}
}
}
}
$returnArray['allOrder'] = $orderArray;
return $returnArray;
}
?>
我尝试了以下:
我已使用此answer来了解如何在while循环之外引用和更新数组
我试过在这样的while循环中检查$ inProgressArray是否为空。
while($inProgressArray = mysql_fetch_array($inProgressResult,MYSQL_ASSOC)||empty($inProgressArray))
但是,leg_prod_inprogress中有一个项目,并且它没有显示在循环外的$ inProgressArray中。
编辑16/11/17 16:13 GMT:添加了legProductionAllRecords.php的详细信息
Editted 2 17/11/17 08:43 GMT:添加了函数返回数组的return语句