0

好的,这是我的模型,它将所有内容返回到我的控制器并转发到我的视图。我得到了正确的行输出,但我也得到了这个奇怪的未定义偏移错误。

模型

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; ?>

该网页正确显示我的数据,但随后显示此未定义的输出错误

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]; ?>
4

2 回答 2

2

在您的函数中,您必须计算结果。目前在您的视图中,您计算​​字段而不是结果。添加 1 个数据键计数并在视图中使用它。

................................................
                    $data['cTier'][] = $row->customerTier;      
                    $data['mySalesRepId'][] = $row->SalesRepId;
                }
                $data['counts'] = $query->num_rows;
            } 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 = isset($optimum['counts']) ? $optimum['counts']:0; ?>
于 2013-04-06T22:46:10.510 回答
0

您的 count($optimum) 为您提供字段的计数(它是一个包含数组的哈希图,例如 $optimum = array("x" => array(1,2), "y" => array(1,2)) 和依此类推)而不是列。您要么必须更改将项目附加到数组的方式,要么更改计数器的工作方式。count($optimum["Firstname"] 可能会成功)

于 2013-04-06T22:54:02.643 回答