0

我正在尝试运行此代码..但我收到一条错误消息..

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


}
?>

谁能告诉我怎么了???

4

1 回答 1

0

尝试做:

$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
}
于 2013-02-07T10:47:58.810 回答