我的控制器功能是
public function listAction()
{
$params = array('host' =>'localhost',
'username' =>'root',
'password' =>'',
'dbname' =>'zend'
);
$DB = new Zend_Db_Adapter_Pdo_Mysql($params);
$DB->setFetchMode(Zend_Db::FETCH_OBJ);
$sql = "SELECT * FROM `user` ORDER BY user_name ASC";
$result = $DB->fetchAssoc($sql);
echo count($result);
$this->view->assign('title','Member List');
$this->view->assign('description','Below, our members:');
$this->view->assign('datas',$result);
}
和 phtml 文件正在获取 mysql 表
<?php
$datas = $this->datas;
for($i = 1; $i<= count($datas);$i++)
{ echo $datas[$i]['id'];
echo $datas[$i]['user_name'];
echo $datas[$i]['first_name'];
echo $datas[$i]['last_name'];
} ?>
它显示未定义偏移量 = 1 的错误,如果我从 2 开始 for 循环它是好的,并显示少一行形式的 mysql 表。
请帮忙,我没有得到错误的地方