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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:44:36+00:00 2026-05-24T19:44:36+00:00

I’m trying to take my result set and send it to the view so

  • 0

I’m trying to take my result set and send it to the view so that it can be displayed accordingly and I”m having problems understanding the docs found here I have a template view of what I’d like it to somehow display like: That just gives you an idea. Below the template or what not is the code for my controller and the model that gets the category names from the database. Also is included is what I have currently for my view (php syntax is wrong).

http://codeigniter.com/user_guide/database/results.html

<div class="menu">
        <ul class="clear">
            <li class="active"><a href="/">Dashboard</a></li>
            <li><?php echo anchor('cpanel/modules/articles', 'Articles'); ?></li>
            <li><a href="styles.html">Styles</a></li>
            <li><a href="tables.html">Tables</a></li>
            <li><a href="charts.html">Charts</a></li>
            <li><a href="gallery.html">Image Gallery</a></li>
            <li><a href="settings.html">Settings</a></li>
        </ul>
    </div>

Controller:

function index()
{
    $id = $this->tank_auth->get_user_id();
    $data = $this->Dashboard->get_user_info($id);
    $rows = $this->Dashboard->get_menu_categories();
    $this->template->set_layout('cpanel')->enable_parser(false);
    $this->template->set('data', $data);
    $this->template->set('menu_categories', $rows);
    $this->template->set_partial('header', 'partials/header');  
    $this->template->set_partial('sidebar', 'partials/sidebar');  
    $this->template->set_partial('content', 'partials/content');      
    $this->template->set_partial('footer', 'partials/footer');
    $this->template->build('/cpanel/index');
}

Model:

/**
 * Get menu categories
 *
 * @param   none
 * @param   none
 * @return  object
 */
function get_menu_categories()
{
    $this->db->select('*');
    $this->db->from('menu_categories');
    $this->db->where('status_id', '1');
    $this->db->order_by('sort_order', 'desc'); 

    $query = $this->db->get();

    return $row = $query->result_array(); 
} 

View:

<div class="menu">
        <ul class="clear">
            <?php
            foreach ($row as $row)
            {
               echo "<li>" anchor('".$row['linkURL']."', '$row['category_name']')"</li>";
            }
            ?>                
        </ul>
    </div>

EDIT: Here is my new code. I”m getting the following error message: Severity: Notice

Message: Undefined variable: rows

Filename: partials/header.php

Line Number: 34
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: partials/header.php

Line Number: 34

Controller:

function index()
{
    $id = $this->tank_auth->get_user_id();
    $data = $this->Dashboard->get_user_info($id);
    $menu_data['rows'] = $this->Dashboard->get_menu_categories();
    $this->template->set_layout('cpanel')->enable_parser(false);
    $this->template->set('data', $data);
    $this->template->set('menu_categories', $menu_data);

    $this->template->set_partial('header', 'partials/header');  
    $this->template->set_partial('sidebar', 'partials/sidebar');  
    $this->template->set_partial('content', 'partials/content');      
    $this->template->set_partial('footer', 'partials/footer');
    $this->template->build('/cpanel/index');
}

Model:

/**
 * Get menu categories
 *
 * @param   none
 * @param   none
 * @return  object
 */
function get_menu_categories()
{
    $this->db->select('*');
    $this->db->from('menu_categories');
    $this->db->where('status_id', '1');
    $this->db->order_by('sort_order', 'desc'); 

    $query = $this->db->get();

    return $query->result_array();
}   

View

<div class="menu">
        <ul class="clear">
            <?php
            foreach ($rows as $row)
            {
                echo '<li>'.anchor($row['category_name'], $row['category_name']).'</li>';
            }
            ?>                
        </ul>
    </div>
  • 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-24T19:44:37+00:00Added an answer on May 24, 2026 at 7:44 pm

    Change the last line of get_menu_categories() to return $query->result_array();, the $row variable here does not affect the return value or do anything outside the scope of the function.

    Assuming that $this->template->set() takes an associative array as the second parameter, which is likely the case, change it to:

    $menu_data['rows'] = $this->Dashboard->get_menu_categories();
    //          ^^^^ This is your variable name to be used in the view
    $this->template->set('menu_categories', $menu_data);
    

    Then you should be able to access $rows from the menu_categories view:

    As noted in the comments, use $rows with an s:

    foreach ($rows as $row)
    {
       echo '<li>'.anchor($row['linkURL'], $row['category_name']).'</li>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

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.