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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:40:32+00:00 2026-05-19T03:40:32+00:00

I am currently working on a private messaging system. Right now I’m coding the

  • 0

I am currently working on a private messaging system. Right now I’m coding the inbox and have put 2 rows of temporary data in my messages table to test the inbox is working correctly.

I am trying to return all rows where this query is true:

<?php
class Messages_model extends CI_Model {


    public function inbox()
    {
        $user_id = $this->session->userdata('user_id');
        $username = $this->session->userdata('username');

        return $this->db->query("SELECT * FROM messages WHERE to_id = $user_id AND to_user = '$username'"); //to_id = id of currently logged in and to_user = username
    }
}

Here’s my controller. I’m currently only having one row returned even though both rows should be returned. I have created both rows in the db with the to_id and to_user equal to my session data. So they should both be returned not just one. When I use row_array the first row is returned as explained in CI user guide. When I use result_array() still only one row is returned.

What I want to do is create a table in html with a few columns and 1 row for title of each column e.g. subject, status, date. Then the row underneath will be the actual subject data and status of the message. Then I want to run a while or foreach loop that will echo that empty row each time a row is returned from the messages table for the inbox.

Here is my controller:

<?php
class Messages extends Public_Controller {
    public function  __construct() {
        parent::__construct();

        $this->load->model('messages_model');

    }

    public function inbox()
    {


        $query = $this->messages_model->inbox(); // return from model which is basically a row from messages table
        if ($query->num_rows() != 0) // if rows returned is equal to 1

        {       
        foreach ($query->result_array() as $row) // give array variable the value row_array

        // grab specific elements from row and assign to variables
        $row['id'];
        $row['to_id'];
        $row['to_user'];
        $row['from_id'];
        $row['from_user'];
        $row['time_sent'];
        $row['subject'];
        $row['message'];
        $row['opened'];
        $row['replied'];

        $this->load->view('messages/inbox', $row);
        }

       else
        {
            echo "You have 0 messages in your inbox";
        }
    }
}

I hope I was clear with explain what I’m trying to do.
Thanks in advance.

  • 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-19T03:40:33+00:00Added an answer on May 19, 2026 at 3:40 am

    First, bear in mind that I am not very familiar with CodeIgniter. Your problem, however, is fairly generic PHP:

    foreach ($query->result_array() as $row) // give array variable the value row_array
    
        // grab specific elements from row and assign to variables
        $row['id'];
        $row['to_id'];
        $row['to_user'];
        $row['from_id'];
        $row['from_user'];
        $row['time_sent'];
        $row['subject'];
        $row['message'];
        $row['opened'];
        $row['replied'];
    
        $this->load->view('messages/inbox', $row);
    }
    

    Every time you encounter a row, you’re calling $this->load->view(). I believe you should only be calling the view once, with all the data you want to pass. You probably want to do something like this:

    $data = array();
    foreach ($query->result_array() as $row) {
        $data[] = array (
            'id' => $row['id'],
            'to_id' => $row['to_id'],
            'to_user' => $row['to_user'],
            'from_id' => $row['from_id'],
            'from_user' => $row['from_user'],
            'time_sent' => $row['time_sent'],
            'subject' => $row['subject'],
            'message' => $row['message'],
            'opened' => $row['opened'],
            'replied' => $row['replied']
        );
    }
    $this->load->view('messages/inbox', $data);
    

    You would then need to process multiple messages in your view.

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

Sidebar

Related Questions

We are currently working in a private beta and so are still in the
The system I am currently working on requires some role-based security, which is well
Trying to programmatically get the private working set of a process. Currently I am
I am working on an application that uses a private web service. We currently
I currently working on an issue tracker for my company to help them keep
I am currently working on a project and my goal is to locate text
I'm currently working on creating a new C# project that needs to interact with
I am currently working on a project with specific requirements. A brief overview of
I'm currently working at a small web development company, we mostly do campaign sites
The company I'm currently working for is using Selenium for Uniting-Testing our User Interface.

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.