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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:45:45+00:00 2026-06-11T21:45:45+00:00

Here is my model – I want to assign the rows and echo out

  • 0

Here is my model – I want to assign the rows and echo out on the view page e.g <?php echo $product?>

class Model_products extends CI_Model {

    function printer()
    {

    $id = $this->uri->segment(3, 0);

        $q = $this->db->get_where('printer', array('id' => $id));

        if ($q->num_rows == 1)
        { 
            foreach ($q->result() as $row)
            {

                echo $row->name; # THIS WORKS
                $data['product'] = $row->name;  # THIS DOES NOT WORK
                $data['desc'] = $row->description;
                $data['size'] = $row->size;
                $data['options'] = $row->options;
                $data['more'] = $row->more_info;
            }
        }


    }
}

Here’s my controller

public function products()
{

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

    $this->Model_products->printer();

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

    $this->load->view('pricing');
}

My view is

<h1>
<?php echo $product; ?>
</h1>

<p>
<?php echo $desc; ?>
</p>


<h3>
Size
</h3>
<p>
<?php echo $size; ?>
</p>

How do I properly pass my model array to my controller so that I can echo out on my view?

  • 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-11T21:45:47+00:00Added an answer on June 11, 2026 at 9:45 pm

    Simply return $data to controller

    class Model_products extends CI_Model {
    
        function printer()
        {
            $data   =   array();
            $id = $this->uri->segment(3, 0);
    
            $q = $this->db->get_where('printer', array('id' => $id));
    
            if ($q->num_rows == 1)
            { 
                foreach ($q->result() as $row)
                {
    
                   // echo $row->name; # THIS WORKS
                    $data['product'] = $row->name;  # THIS DOES NOT WORK
                    $data['desc'] = $row->description;
                    $data['size'] = $row->size;
                    $data['options'] = $row->options;
                    $data['more'] = $row->more_info;
                }
            }
    
        return $data;
        }
    }
    

    No win Controller

    public function products()
    {
    
        $this->load->model('Model_products');
    
        $data['products']   =   $this->Model_products->printer();
    
        $this->load->view('products', $data);
    
        $this->load->view('pricing');
    }
    

    And in view

    <?   
       echo '<pre>';
       print_r($products);
    ?>
    

    EDIT Also correct your model code.

            foreach ($q->result() as $row)
            {
    
                echo $row->name; # THIS WORKS
                $data[]['product'] = $row->name;  # THIS DOES NOT WORK
                $data[]['desc'] = $row->description;
                $data[]['size'] = $row->size;
                $data[]['options'] = $row->options;
                $data[]['more'] = $row->more_info;
            }
    

    If you are not using multidimensional array it will overwrite the last record.

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

Sidebar

Related Questions

Here is my model: public class RestoreRequestModel : IDataErrorInfo { //true seems Value contains
Here's sample model classes, which being use with Entity Framework Code First: public class
Here's my model: public class StockRequestModel { public int StockID { get; set; }
Here is my Model View and Collection : window.Report = Backbone.Model.extend({}); window.ReportCollection = Backbone.Collection.extend({
here is my model class gameUserTrophyInfo(models.Model): user = models.ForeignKey(userInfo) trophy = models.ForeignKey(gameTrophyInfo) date =
Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True)
Here's my user model: class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,
Here is model structure: Client is User, Client can be corporate or person: class
Here's my entity framework model: Here's the domain service class dialog: I can't select
I have a criteria query not really working. Here the model: @Entity public class

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.