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

  • Home
  • SEARCH
  • 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 6596687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:06:31+00:00 2026-05-25T18:06:31+00:00

I am relatively experienced PHP developer. I have chosen the CodeIgniter framework. So far

  • 0

I am relatively experienced PHP developer.

I have chosen the CodeIgniter framework. So far I have understood how it is used. Until now, I want to be able to do a while loop.

Within my controller I have:

$this->load->model('Test');
$data['result'] = $this->Test->getInfo();
$this->load->view('index1', $data);

In my Model I have:

$result = mysql_query("SELECT * FROM users WHERE last_name='Hart'")or die(mysql_error());  
$row = mysql_fetch_array( $result );    
return $row;

And in my View:

echo $result[0];

However, this only outputs the first field within the first row found.

Please could you help me with retrieving the information from a database – while loop.

Does the while loop happen in the Model? Am I just echoing out the result correctly?

  • 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-25T18:06:32+00:00Added an answer on May 25, 2026 at 6:06 pm

    There’s actually a much easier way to do what you want to do using the ActiveRecord class that CodeIgniter includes which will allow you to just return an array of results. Here’s the documentation.

    Your model would become:

    $this->db->where('last_name','Hart');
    $result = $this->db->get('users');
    return $result->result_array();
    

    You may also have to setup your database in application/config/database.php, and also load the database class in application/config/autoload.php:

    $autoload['libraries'] = array('database');
    

    To display this information, using the MVC pattern properly your controller should pass the information it gets from the model to a view. To do this generally you do this:

    $data['myinfo'] = $this->test->getInfo();
    $this->load->view('test_view',$data);
    

    Then you have to create a view like so in applications/views/test_view.php:

    <h1>Some HTML goes here</h1>
    <?php
    foreach($myinfo as $row) {
        echo $row['field'];
    }
    ?>
    <p>Some more HTML goes here</p>
    

    I suggest you read the CodeIgniter User Guide before diving into creating an application as CodeIgniter includes libraries that greatly simplify and speed up the whole process.

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

Sidebar

Related Questions

I am relatively new to PHP, but experienced Java programmer in complex enterprise environments
Im an experienced actionscript developer, and relatively new to Objective C. I decided a
i am relatively experienced in Java coding but am new to C++. I have
I'm an experienced coder, but am still relatively new to the STL, and have
I'm relatively new to version control, and so far only have experience working with
I'm fairly new to PHP and MySQL (experienced with other languages). Basically I want
Possible Duplicate: PhpMailer vs. Swiftmailer? I have always used PHP's built in mail() function
Hi there I am desktop application developer but now i have to work on
I'm a relatively experienced .NET/iOS developer taking first steps in Android development - to
I work on relatively sensitive code that we wouldn't want falling into the wrong

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.