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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:12:49+00:00 2026-06-15T10:12:49+00:00

Instead of my messages appearing on the screen I just see this: A PHP

  • 0

Instead of my messages appearing on the screen I just see this:

A PHP Error was encountered

Severity: Warning
Message: Invalid argument supplied for foreach()

This is despite my foreach loop in my view page looking ok:

foreach($messages as $message):// this is the line causing the error
      $delete = $message['message_id']; // i've even tried removing this line to no avail
      //var_dump($message); ?>
          <li><?=$message['from']?> says...: "<?=$message['message']?>"(<?=anchor("home/deleteMsg/$delete", 'delete')?>)</li>      
         <?php endforeach?> 

Here is my model:

class Messages extends CI_Model
 {



function Messages()
{
parent::__construct();
}


function deleteMsg($message_id) // this message_id is the id field for each message in my database
       {


              $record = array('message_id' => $message_id); 
              $this->db->delete('messages', $record); 
      } 



  function addMessage($message_id, $from, $to, $message)//this fields come after the message_id field in the database
   {
$record = array(

        'to' => $to,
        'from' => $from,
        'message' => $message);
$this->db->insert('messages', $record); 

   }

   function getMessages($user)
   {

$this->db->select('*');
$this->db->from('messages');
$this->db->where('to', $user);
$messagesSet = $this->db->get();

$messages = array ();

foreach ($messagesSet->result() as $row)
{
    $messages[] = array(

             'from'    => $row ->from,
             'message' => $row ->message);

}       
    return $messages;

  }

 }

Here is my controller:

 class Home extends CI_Controller 
 {
  function Home()
 {
  parent::__construct();
  $this->load->model('messages');
  $this->load->model('friends');
  $this->load->model("profiles");


  }

  function drop($member)
  {
   $username = $this->session->userdata('username');
   $this->friends->deleteFriend($username, $member);
   redirect('home');
  }



     function deleteMsg($messageid) {

    $this->messages->deleteMsg($messageid);

    redirect('home');

      }


function index()
{

 $username = $this->session->userdata('username');
 $membername = $this->session->userdata('membername');
 $viewData['membername'] = $membername;
 $viewData['username'] = $username;
 $viewData['following'] = $this->friends->getFollowing($username);
 $viewData['followers'] = $this->friends->getFollowers($username);
 $viewData['messages'] = $this->messages->getMessages($membername);
 $viewData['friends'] = $this->friends->getFriends($username);
 $viewData['messages'] = $this->messages->deleteMsg($membername);

 $this->load->view('shared/header');
 $this->load->view('home/hometitle', $viewData);
 $this->load->view('shared/nav');
 $this->load->view('home/homeview', $viewData);
 $this->load->view('shared/footer');
}


 }  
  • 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-06-15T10:12:50+00:00Added an answer on June 15, 2026 at 10:12 am

    Your $messages is empty because it’s overwritted with this:

    $viewData['messages'] = $this->messages->deleteMsg($membername);
    

    in the index function.

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

Sidebar

Related Questions

Can I copy only the error message from Eclipse Problems with instead of this
Instead of showing an error message 'Name is required' I would like to change
I try to localize error messages from the Domain classes. This is possible with
In a Silverlight application, instead of consuming and writing (wcf) wrappers around messages that
Is there a way to view the latest debug message instead of having to
Please can i use datacontracts in WCF for streaming instead of message Contract. If
I have some complex message to show inside of a flash message so instead
Instead of throwing new Exception(Some message, maybeSomeCause) , which means that all callers of
I understand that in my unit test I should do BOOST_TEST_MESSAGE(message); instead of std::cout
If no messages were found in an array then it is returning 2 instead

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.