Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6885233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:36:32+00:00 2026-05-27T05:36:32+00:00

The code for index.phtml as follows: <?php foreach ($this->entries as $entry): ?> <?php echo

  • 0

The code for index.phtml as follows:

<?php foreach ($this->entries as $entry): ?>
    <?php echo $this->escape($entry->email) ?>
    <br></br>
    <?php echo $this->escape($entry->comment) ?>
<?php endforeach ?>

The code for indexAction() in IndexController:

public function indexAction()
{

    $guestbook = new Application_Model_HRModel();
    $view = new Zend_View(array('scriptPath' =>'C:/Users/398853/Documents/NetBeansProjects/PhpProject3/application/views/scripts/index'));
    $view->entries = $guestbook->fetchAll();
    echo $view->render('index.phtml');

}

The code for fetchAll() in Application_Model_HRModel:

    public function fetchAll() 
   {
       $entry = new Application_Model_HRMo();
       $resultSet = $this->getDbTable()->fetchAll();
       $entries   = array();
       foreach ($resultSet as $row) {
        $entry->setId($row->id);
        $entry->setEmail($row->email);       
        $entry->setCreated($row->created);
        $entry->setComment($row->comment);
        $entries[] = $entry;
    }

            return $entries;

}
I have 3 entries i.e. 3 rows in my databse table .
But When i request the url as http://localhost:8888/Index it says
Warning: Invalid argument supplied for foreach() in C:\Users\39885Documents\NetBeansProjects\PhpProject3\application\views\scripts\index\index.phtml on line 54 and then display last row’s entry 3 times.I think problem occurs because at first it executes index.phtml and without executing indexAction()(which further executes fetchAll()) $entries will not an array Thats Why at first it gives above stated warning. Now tell me how to start execution from indexAction() then come at index.phtml so that $entries would be an array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:36:32+00:00Added an answer on May 27, 2026 at 5:36 am

    In fetchAll() you use the same object, but you should create new in loop. That’s why you have 3 duplicated rows in output. About PHP warning – tru to var_dump($this->entries) and check the type

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code for indexAction() in AdminLoginController is: $form_object = new Application_Form_NewProfile(); $form_object->setAction('/adminlogin/index'); $form_object->setMethod('post'); $this->view->form =
I have the following code in my index view. latest_entry_list = Entry.objects.filter(is_published=True).order_by('-date_published')[:10] for entry
include 'header.php'; // ... some code header('Location:index.php'); exit; The above code keeps giving me
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
http://sandbox.jinoh.dk/magento/index.php/produkter This is the link where I develop a Magento webshop for a client.
Lets assume the following code within a controller: $this->view->addScriptPath('dir1/views/scripts'); $this->view->addScriptPath('dir2/views/scripts'); $this->render('index.phtml'); Where dir1/views/scripts contains
within my login code (index.php) there is a section for facebook login. it checks
i want manage result of ajax in phtml file, this is my view code
I have the code below that should copy the file index.php to the directory
I downloaded the package http://nodebox.net/code/index.php/Linguistics#verb_conjugation I'm getting an error even when I tried to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.