これが私のモデルです。これはすべてをコントローラーに返し、ビューに転送します。正しい行出力が得られますが、この奇妙な未定義のオフセット エラーも発生します。
モデル
function getAllCustomersPendingInstall()
{
$data=array();
//Need to use sessions to display proper
//records for each user. Temp set id to user #7
$id = 7;
//query the db and return all record where SalesRepId == $id
$query = $this->db->get_where('customers', array('SalesRepId' => $id));
//check logic, if rows exist RETURN all rows, else
//return message that no pending installs is available.
if($query->num_rows >= 0) {
foreach($query->result() as $row) {
$data['cFirstName'][] = $row->customerFirstName;
$data['cLastName'] [] = $row->customerLastName;
$data['cId'][] = $row->customerId;
$data['cStatus'][] = $row->customerStatus;
$data['cDateSold'][] = $row->customerDateSold;
$data['cCorp'][] = $row->customerCorp;
$data['cAccount'][] = $row->customerAccount;
$data['cAddress'] [] = $row->customerAddress;
$data['cAptNum'][] = $row->customerCity;
$data['cState'][] = $row->customerState;
$data['cZip'][] = $row->customerZip;
$data['cEmail'][] = $row->customerEmail;
$data['cHomePhone'][] = $row->customerHomePhone;
$data['cCellPhone'][] = $row->customerCellPhone;
$data['cInstallDate'][] = $row->customerInstallDate;
$data['cInstallTime'][] = $row->customerInstallTime;
$data['cServiceLevelSold'][] = $row->customerServiceLevelSold;
$data['cWinBackFrom'][] = $row->customerWinBackFrom;
$data['cSaleSource'][] = $row->customerSaleSource;
$data['cTier'][] = $row->customerTier;
$data['mySalesRepId'][] = $row->SalesRepId;
}
} else {
$data = "No pending installs available!";
return $data;
}
//the following var_dump is only showing the last record.
//need to show all rows (which should be 2)
//var_dump($data); exit;
return $data;
}
見る
<?php $dataNumRows = count($optimum); ?>
<?php for ($i = 0; $i < $dataNumRows; $i++) : ?>
<?php echo $optimum['cFirstName'][$i]; ?>
<?php echo $optimum['cLastName'][$i]; ?>
<?php echo $optimum['cId'][$i]; ?>
<?php echo $optimum['cStatus'][$i]; ?>
<?php echo $optimum['cDateSold'][$i]; ?>
<?php echo $optimum['cCorp'][$i]; ?>
<?php echo $optimum['cAccount'][$i]; ?>
<?php echo $optimum['cAddress'][$i]; ?>
<?php echo $optimum['cAptNum'][$i]; ?>
<?php echo $optimum['cState'][$i]; ?>
<?php echo $optimum['cZip'][$i]; ?>
<?php echo $optimum['cEmail'][$i]; ?>
<?php echo $optimum['cHomePhone'][$i]; ?>
<?php echo $optimum['cCellPhone'][$i]; ?>
<?php echo $optimum['cInstallDate'][$i]; ?>
<?php echo $optimum['cInstallTime'][$i]; ?>
<?php echo $optimum['cServiceLevelSold'][$i]; ?>
<?php echo $optimum['cWinBackFrom'][$i]; ?>
<?php echo $optimum['cSaleSource'][$i]; ?>
<?php echo $optimum['cTier'][$i]; ?>
<?php echo $optimum['mySalesRepId'][$i]; ?>
<br>
<?php endfor; ?>
Web ページにはデータが正しく表示されていますが、この未定義の出力エラーが表示されます
Tom Jones 1 4 02/11/2013 77 895482 1823 e15th St Brooklyn NY 11268 tones728@verizon.net 0000000000 0000000000 02/16/2013 1 11 1 1 1 7
Alexa Planter 2 4 02/13/2013 77 632584 5847 w79th Ave Brooklyn NY 11258 aplanter222@gmail.com 0000000000 0000000000 02/22/2013 1 31 1 1 2 7
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2
Filename: views/welcome_message.php
Line Number: 29
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2
Filename: views/welcome_message.php
Line Number: 30
.... repeated to line 49
エラーの原因となっている行は次のとおりです。
29| <?php echo $optimum['cFirstName'][$i]; ?>
30| <?php echo $optimum['cLastName'][$i]; ?>
..| <?php echo $optimum['cId'][$i]; ?>
<?php echo $optimum['cStatus'][$i]; ?>
<?php echo $optimum['cDateSold'][$i]; ?>
<?php echo $optimum['cCorp'][$i]; ?>
<?php echo $optimum['cAccount'][$i]; ?>
<?php echo $optimum['cAddress'][$i]; ?>
<?php echo $optimum['cAptNum'][$i]; ?>
<?php echo $optimum['cState'][$i]; ?>
<?php echo $optimum['cZip'][$i]; ?>
<?php echo $optimum['cEmail'][$i]; ?>
<?php echo $optimum['cHomePhone'][$i]; ?>
<?php echo $optimum['cCellPhone'][$i]; ?>
<?php echo $optimum['cInstallDate'][$i]; ?>
<?php echo $optimum['cInstallTime'][$i]; ?>
<?php echo $optimum['cServiceLevelSold'][$i]; ?>
<?php echo $optimum['cWinBackFrom'][$i]; ?>
<?php echo $optimum['cSaleSource'][$i]; ?>
..| <?php echo $optimum['cTier'][$i]; ?>
49| <?php echo $optimum['mySalesRepId'][$i]; ?>