简体   繁体   中英

Zend Framework Error Notice

I'm trying to run this code.. But I get an error saying..

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

This is my code...

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


}
?>

Can anyone please tell me what is wrong???

try doing:

$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
}

If you are fetching a single row, then you could do:

$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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM