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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:41:31+00:00 2026-05-23T09:41:31+00:00

I am a beginner to codeIgniter and have looked for an answer to this

  • 0

I am a beginner to codeIgniter and have looked for an answer to this on the CI forums and google, and even here…

OK I have searched for this and every time I find answers to this pertaining to use a foreach() to get the data out of the array then do something with it in the foreach loop; this is not what i wish to do.

I am building a site whereby I would like to store site information, such as site title, description, abstract, keywords etc in a database table with just one row (rather than having to go to the html and do it there..)

So far I have something like this in my model:

    function getAll(){
    $q = $this->db->get('system');

    if($q->num_rows() > 0){
            return $q->row();
    }
}

in my controller I have:

function index(){
    $this->load->model("system_model");
    $data[] = $this->system_model->getAll();    
    $this->load->view('home', $data);
}

and in my view I wish to have very simply (html tags are descriptive only):

   <title><?php echo $this->title; ?></title>
<description><?php echo $this->description; ?></description>

As you can see a foreach loop would not work in this instance and I don’t believe that the best way to do this is loop through the array in the controller and then pass each individual array part into the view as a separate variable..

Is this at all possible?

EDIT

I have given the tick to the first answer as that put me on the right track to find the solution (although it might not be 100% correct its working) in order to get this to work I followed answer number 1, but then in the view I did the following:

<title><?php echo$system[0]->title; ?></title>
  • 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-23T09:41:31+00:00Added an answer on May 23, 2026 at 9:41 am

    Give the $data[] array a key name

    function index(){
        $this->load->model("system_model");
        $data['mydata'] = $this->system_model->getAll();    
        $this->load->view('home', $data);
    }
    

    and in the view file you can echo or loop or whatever based on that key

    echo $mydata
    

    or

    foreach($mydata as $md){
    echo $md
    }
    

    The best way to query the database in the model is to do the following:

    function get_user_by_id($id){
        $this->db->where('id', $id);
        $query = $this->db->get('users');
        $result = $query->result_array();
        return $result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner here: In this answer to my question of how to insert data into
Beginner at Django here, I've been trying to fix this for a long time
Absolute beginner question: I have a template file index.html that looks like this: ...
Beginner here. Why is this an endless loop ? for (p = 0; p
Beginner programmer here....hope it makes sense :) I have created a console app that
Beginner here, I have a simple question. In Android what would be the best
Beginner here See - http://www.w3schools.com/js/tryit.asp?filename=try_dom_tablerow_cells In this example, when change content is pressed, new
SQL beginner here. I have a query which takes around 10 seconds to run,
OOP beginner here and my problem is when i get to this event :
Beginner programmer here. So bear with me. I have a simple python program. print

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.