我试图将数组分配给另一个数组问题是它一直声明未定义的偏移量。虽然当我回答其他变量时,它们的格式与有问题的变量类似,但它们可以正常显示。请帮忙。谢谢。
function searchAllIncoming(){
$rows[] = array();
$rows2[] = array();
$rows3[] = array();
$i = 0;
$companyName = $this->db->query("SELECT id, name from company");
foreach($companyName->result_array() as $row2){
$rows2[$i]['id'] = $row2['id'];
$rows2[$i]['name'] = $row2['name'];
$i++;
}
//get all company names
$i = 0;
$staffName = $this->db->query("SELECT id, surname, firstName, middleInitial from employee");
foreach($staffName->result_array() as $row3){
$rows3[$i]['id'] = $row3['id'];
$rows3[$i]['name'] = $row3['surname'].", ".$row3['firstName']." ".$row3['middleInitial'];
$i++;
}
//get all employee names
$i= 0;
$output = $this->db->query("SELECT * from incoming ORDER BY incomingId LIMIT 20");
foreach($output->result_array() as $row){
$count = 0;
$j = 0;
$rows[$i]['incomingId'] = $row['incomingId'];
$rows[$i]['referenceNo'] = $row['referenceNo'];
$rows[$i]['documentTypeId'] = $row['referenceNo'];
$rows[$i]['documentDate'] = $row['documentDate'];
$rows[$i]['dateReceived'] = $row['dateReceived'];
$rows[$i]['sender'] = $row['sender'];
while($count < sizeof($rows2)){
if($rows2[$j]['id'] != $row['companyId']){
$j++;
} else {
$rows[$i]['companyName'] = $rows2[$j]['name'];
break;
}
}
$j= 0;
while($count < sizeof($rows3)){
if($rows3[$j]['id'] != $row[$i]['responsibleStaffId']){
$j++;
} else {
$rows[$i]['responsibleStaffName'] = $rows3[$j]['name'];
break;
}
}
$rows[$i]['subject'] = $row['subject'];
$rows[$i]['actionDone'] = $row['actionDone'];
$rows[$i]['track'] = $row['track'];
$rows[$i]['completed'] = $row['completed'];
$rows[$i]['remarks'] = $row['remarks'];
$i++;
}
return $rows;
}
我的错误发生在:
$rows[$i]['responsibleStaffName']
and
$rows[$i]['companyName']
答案 0 :(得分:0)
你的代码中有两个while循环,它可能带有无限循环。 如果“if condition”总是计算为true,那么它肯定是一个无限循环。请在每次循环后增加$ count值,如下所示。
while($count < sizeof($rows2)){
if($rows2[$j]['id'] != $row['companyId']){
$j++;
} else {
$rows[$i]['companyName'] = $rows2[$j]['name'];
break;
}
++$count;
}
请尝试使用上面的代码,它可能会帮助您调试实际故障的位置。
答案 1 :(得分:0)
这行代码:
$rows3[$j]['id'] != $row[$i]['responsibleStaffId'];
应该只是
$rows3[$j]['id'] != $row['responsibleStaffId'];