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 4621614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:43:36+00:00 2026-05-22T02:43:36+00:00

I want to populate all the data from my database to a table using

  • 0

I want to populate all the data from my database to a table using <?php foreach; ?> but I can’t get it to work. Please check my code:

controller
$data['query'] = $this->db->query('SELECT * FROM users');
$this->load->view('users_view',$data);

View
<?php foreach ($query->result_array() as $row)
{ ;?>
<tr>
<td><?php echo $row['usrID'];?></td>
<td><?php echo $row['usrName'];?></td>
<td><?php echo $row['usrPassword'];?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
  • 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-22T02:43:37+00:00Added an answer on May 22, 2026 at 2:43 am

    I would reccommend the alternative syntax for your foreach in the view…

    It looks like you should be having some syntax errors the way you have it.

    <?php foreach ($query->result_array() as $row): ?>
        <tr>
            <td><?php echo $row['usrID'];?></td>
            <td><?php echo $row['usrName'];?></td>
            <td><?php echo $row['usrPassword'];?></td>
        </tr>
    <?php endforeach; ?>
    

    EDIT – to point out your syntax issues.

    <?php foreach ($query->result_array() as $row)
    { ;?> //<---- semicolon?
    <tr>
    <td><?php echo $row['usrID'];?></td>
    <td><?php echo $row['usrName'];?></td>
    <td><?php echo $row['usrPassword'];?></td>
    </tr>
    <?php } ?>
    <?php endforeach; ?> //<--- no need for this when using regular foreach
    

    This first semicolon would be like writing a foreach like this…

    foreach ($array as $ele) { ; //<--this would throw an error just like it should above.
        //do stuff
    }
    

    Opinion aside from the point of the question

    You should be processing your data in the controller and simply sending an array of data to be displayed in the view, not the whole query object.

    so…

    Controller

    $query = $this->db->query('SELECT * FROM users');
    $data['users'] = $query->result_array();
    $this->load->view('users_view',$data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table layout that I want to populate with the result from
What I want to do is retrieve all emails from MS SQL Customer table
I want to populate a table, defined in layout xml file through the programmatic
I want to populate a drop down menu with a column from a MySQL
From the admin panel I want to populate a slug field based on a
I have an xml data file and I want to populate a listview in
Is there an equivalent of .NET's data binding in Qt? I want to populate
I am coming from a novice database programmer background, mainly using MS Access for
PLATFORM: PHP, mySQL & jQuery WHAT I HAVE: I have a Database table. Within
I am creating an iOS app that reads data from a single SQLITE table

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.