Php Zend框架错误通知

Php Zend框架错误通知,php,mysql,zend-framework,Php,Mysql,Zend Framework,我正在尝试运行此代码。。但是我有一个错误,说 Notice: Undefined offset: 0 in C:\wamp\www\address\application\views\scripts\index\index.phtml on line 64 Call Stack # Time Memory Function Location 1 0.0006 374544 {main}( ) ..\index.php:0 2 0.0866 4624240 Ze

我正在尝试运行此代码。。但是我有一个错误,说

Notice: Undefined offset: 0 in C:\wamp\www\address\application\views\scripts\index\index.phtml on line 64
Call Stack
#   Time    Memory  Function    Location
1   0.0006  374544  {main}( )   ..\index.php:0
2   0.0866  4624240 Zend_Application->run( )    ..\index.php:26
3   0.0866  4624240 Zend_Application_Bootstrap_Bootstrap->run( )      ..\Application.php:366
4   0.0867  4624416 Zend_Controller_Front->dispatch( )  ..\Bootstrap.php:97
5   0.0984  5320368 Zend_Controller_Dispatcher_Standard->dispatch( )    ..\Front.php:954
6   0.1136  5637296 Zend_Controller_Action->dispatch( ) ..\Standard.php:295
7   0.1154  5674032 Zend_Controller_Action_HelperBroker->notifyPostDispatch( )  ..\Action.php:527
8   0.1154  5674792 Zend_Controller_Action_Helper_ViewRenderer->postDispatch( ) ..\HelperBroker.php:277
9   0.1155  5674792 Zend_Controller_Action_Helper_ViewRenderer->render( )   ..\ViewRenderer.php:960
10  0.1166  5675008 Zend_Controller_Action_Helper_ViewRenderer->renderScript( ) ..\ViewRenderer.php:921
11  0.1166  5675008 Zend_View_Abstract->render( )   ..\ViewRenderer.php:900
12  0.1168  5716176 Zend_View->_run( )  ..\Abstract.php:888
13  0.1171  5724528 include(   'C:\wamp\www\address\application\views\scripts\index\index.phtml' )  ..\View.php:108
这是我的密码

<?php
if (isset($_POST['search']))
{

$db = new Zend_Db_Adapter_Pdo_Mysql(array(
'host'     => 'localhost',
'username' => 'root',
'password' => '',
'dbname'   => 'addressdb'
));

$db->setFetchMode(Zend_Db::FETCH_OBJ);
$result = $db->fetchAll('SELECT * FROM user WHERE u_name = ?', $_POST['search']);

echo $result[0]->add1;


echo'<br><br><table width="200px" >';
echo'<tr ><th class="search">Name</th><td class="search">:</td><td class="search">'. $_POST['name'].'</td></tr>';
echo'<tr ><th class="search">Address1</th><td class="search">:</td><td class="search">'.$result[0]->add1.'</td></tr>';
echo'<tr ><th class="search">Address2</th><td class="search">:</td><td class="search">how</td></tr>';
echo'<tr ><th class="search">Address3</th><td class="search">:</td><td class="search">are</td></tr>';
echo'<tr ><th class="search">Telephone</th><td class="search">:</td><td class="search">you..</td></tr></table>';


}
?>

有谁能告诉我出了什么问题吗?

试试看:

$result = $db->fetchAll('SELECT * FROM user WHERE u_name = ?', $_POST['search']);

$countResult = count($result);
if($countResult > 0 ) {
  echo $result->add1;
}
else {
   ..you dont have any records, show some proper message
}
如果要获取单行,则可以执行以下操作:

$result = $db->fetchRow('SELECT * FROM user WHERE u_name = ?', $_POST['search']);
$countResult = count($result);
if($countResult > 0 ) {
   echo $result->add1;
}
else {
   ..you dont have any records, show some proper message
}

echo$result[0]->add1
echo$result->add1您确定查询中有任何结果吗?如果没有,则您无法访问
$result[0]
抱歉,我对Zend真的很陌生。。“查询中的任何结果”是什么意思?我只想根据文本框输入从数据库中检索记录。你还有其他建议吗?总是先帮自己,
debug
你的代码。在上述情况下,您可以通过
var\u dum($result)
检查返回结果。然后尝试根据output.Thanx检索该值。。但是,当我尝试您的代码时,它会进入else部分。并显示以下错误:尝试获取C:\wamp\www\address\application\views\scripts\index\index.phtml中非对象的属性(位于第89行),这意味着您没有sql查询的结果,请尝试将html内容部分(如您的问题所示)放入if条件中,在其他情况下,显示一些信息或适当的东西好的。。塔克斯。我会那样做的。:)