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

The Archive Base Latest Questions

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

Framework : CI Situation: I have this very frustrating problem in codeigniter. here is

  • 0

Framework : CI

Situation:

I have this very frustrating problem in codeigniter.

here is the code:
(Controller)

class sampleController extends CI_Controller {

function index() {
    data['message'] = 'something';

    data['js'] = array('script1.js', 'script2.js');
    data['css'] = array('style1.css', 'style2.css', 'style3.css');

    $this->load->model('user_model');
    $user = $this->input->post('username');

    data['user_id'] = $this->user_model->getUserIdByUsername($user);
    data['user_info'] = $this->user_model->getAllUserInfo($user);

    $this->load->view('someview', $data);

}

}

okay there goes my controller, i passed several data like js, css, user_id and user_info

here are the methods in my model:

getUserIdByUsername($user) {
$this->db->select("id");
$this->db->where("username", $user);
$result = $this->get("users");
return $result->row();

}

getAllUserInfo($user) {
$this->db->select("first_name, last_name, age");
$this->db->where("username", $user);
$result = $this->get("users");
return $result->row();
}

The problem occurs in the view, when i tried to access all the variables that has been passed by the controller

  1. if i tried echoing $message, it will render out correctly like this = something
  2. if i tried looping on each using foreach$js and $css like this

    foreach($js as $key){//echo script here}

    foreach($css as $key){// echo link rel stylesheet here}

it will render out correctly like <script src='script1.js'></script><script ...></script> iterate to all $js same goes with css

but if i tried echoing out $user_id . . it won’t, bec. it is an object.

so to solve for the problem what i did is . .<?php foreach($user_id as $id){} ?> i can echo $id in this case
is there anyway so that i can echo it out simple without that messy foreach.

i understandd that when i comes to $user_info, it is fine to do this foreach($user_info as $key => $value){$info[$key]=$value}
but is there a better way that doing that in the view?

maybe instead of an object, array will be sent before the view can use it?

thanks muchs

Edit: fixed same method name;

  • 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-12T18:44:50+00:00Added an answer on June 12, 2026 at 6:44 pm

    $result->row(); returns an object with all the selected fields. Just because you only SELECTed the id field doesn’t change the return value. Try this instead:

    $data['user_id'] = $this->user_model->getUserIdByUsername($user)->id;
    

    OR:

    getUserIdByUsername($user) {
        $this->db->select("id");
        $this->db->where("username", $user);
        $result = $this->get("users");
        return $result->row()->id;
    }
    

    Check the CI docs for more information about generating query results if you want arrays instead of objects:

    result_array()

    This function returns the query result as a pure array, or an empty
    array when no result is produced.

    row_array()

    Identical to the above row() function, except it returns an array.

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

Sidebar

Related Questions

I'm wondering what is the culturally-acceptable way to handle this code situation. I have
I'm sure this is not a very pythonic situation. But I'm not actually using
I have a situation where I need to place very large number of jars
On this site I have a situation where a user might need to be
Current situation: I have the current version of my MVC Framework which uses classes
I have a very specific problem and i'm looking for input on a good
The situation is like this: I have a WCF host with a duplex nettcpbinding
I'm creating a framework for questionnaires. The questionnaire has several questions. My situation is
Akka framework recommends using typed actor only for interacting with external code. However, standard
Our framework requires wrapping certain functions in some ugly boilerplate code: def prefix_myname_suffix(obj): def

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.