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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:19:47+00:00 2026-05-24T01:19:47+00:00

I have been literally pulling my hair out with this one and its beginning

  • 0

I have been literally pulling my hair out with this one and its beginning to delay the rest of my project and it really is getting me down.

I am trying to populate a pull down using values taken from a database table so that if in the future the user wants to add more options to the pull down they can add them to the table in the database.

I am using the Codeigniter platform (PHP) using MVC design pattern.

Here is the error message I am getting:

A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: views/submit.php Line Number: 139

My Model function is this here which retrieves the rows from the table called “Staff”.
This works fine!

function retrieve_values()
{
    $query = $this->db->get('staff');

    if ($query->num_rows() > 0) 
    { 
        //true if there are rows in the table
        return $query->result_array(); //returns an object of data
    }

    return false;
}

This is the controller function which receives the parameter and passes it to my view.
This works fine!

public function displayform()
{

    //Checks if a user is logged in, if they are not they get redirected -
    if ( $this->session->userdata('name') == FALSE || $this->session->userdata('access_level') == FALSE)
    {
        redirect ('site/index');// to home page
    }

    //Stores the returned array in instance called "formdata" which will be passed to the view to be used in pulldown menu
    $page['formdata']=$this->submit_model->retrieve_values();

    //This loads the form 
    //Instance of "page" in array "page" specifies the file name of the page to load
    $page['page'] = 'submit';
    $this->load->view('template', $page );

    return;
}

This is the part of the view which is causing the problem: I am using a foreach and then echoing the instances of the array into the option.

<select>
    <?php foreach ($formdata as $row) { ?>
        <option value="<?php echo $row->staff_id; ?>"><?php echo $row->name; ?></option>
    <?php } ?>
</select>

printr() of the variable $formdata shows that it contains these values:

Array (
    [0] => Array (
        [staff_id] => 1
        [name] => Cardiology Nurse
    )
    [1] => Array (
        [staff_id] => 2
        [name] => Radiology Nurse
    )
    [2] => Array (
        [staff_id] => 3
        [name] => Scrub Nurse
    )
    [3] => Array (
        [staff_id] => 4
        [name] => Circulating Nurse
    )
    [4] => Array (
        [staff_id] => 5
        [name] => Nurse
    )
    [5] => Array (
        [staff_id] => 6
        [name] => Training Nurse
    )
    [6] => Array (
        [staff_id] => 7
        [name] => Physiologist
    )
    [7] => Array (
        [staff_id] => 8
        [name] => Radiographer
    )
    [8] => Array (
        [staff_id] => 9
        [name] => Consultant
    )
    [9] => Array (
        [staff_id] => 10
        [name] => Radiologist
    )
    [10] => Array (
        [staff_id] => 11
        [name] => Cardiologist
    )
    [11] => Array (
        [staff_id] => 12
        [name] => Anaethestist
    )
    [12] => Array (
        [staff_id] => 13
        [name] => Non-medical Staff
    )
)
  • 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-24T01:19:47+00:00Added an answer on May 24, 2026 at 1:19 am

    formdata is an array of arrays, not objects, so simply change in your view:

    <option value="<?php echo $row->staff_id; ?>"><?php echo $row->name; ?></option>
    // to
    <option value="<?php echo $row['staff_id']; ?>"><?php echo $row['name']; ?></option>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I literally have been pulling my hair out over this for a few days
I've really been pulling me hair out on this for a while and would
I have been at this literally all day. I can create linked lists no
I have literally been searching for this for weeks. I am a novice java
I have been battling with this piece of code for literally days now... Would
Have been working on this question for a couple hours and have come close
I have been working with SQL Server as a Developer a while. One thing
I have been using TortoiseSVN for some time and I really like it. I
Well, I know it may sounds basic, but I have literally been looking everywhere
I have been trying to make my website performs well. One way that may

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.