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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:04:17+00:00 2026-05-27T21:04:17+00:00

Issue/Question : I’m using CodeIgniter to build an event calendar, and I have included

  • 0

Issue/Question: I’m using CodeIgniter to build an event calendar, and I have included a sharing option. This option works at a base level, but only displays the users’ ID (primary key) in an <ul>. This isn’t ideal, and I would like to show the users’ first and last names in the <ul> instead. I thought creating an associative array would work, but I’m receiving funky results. The first and last name echo out as “Array Array” when the page loads, and the URL id comes up as “Array” when you select the “Array Array” link. I’m wondering what is wrong in my logic.

Funky link generated in view:

Array Array

Funky URL that is linked to “Array Array”:

http://example.com/user/shared/view/Array

Modified Controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Shared extends Common_Auth_Controller {

    private $end_user;

    public function __construct()
    {
        parent::__construct();

        $this->end_user = $this->ion_auth->user()->row();
        $data['end_user'] = $this->end_user;
        $this->load->vars($data);

        $this->load->model('events_model', 'events');
    }

    public function index()
    {
        $title['title'] = 'Shared';

        $this->load->model('shared_model','shared');

        $data['sharers'][] = array(
                                'shared_owner_id' => $this->shared->get($this->end_user->id),
                                'owner_first_name' => $this->shared->get($this->end_user->first_name),
                                'owner_last_name' => $this->shared->get($this->end_user->last_name),
                                );

        $this->load->view('public/head_view', $title);
        $this->load->view('user/header_view');
        $this->load->view('user/shared_view', $data);
        $this->load->view('user/footer_view');
    }

Modified View:

<div class="hide-on-phones">
                <ul>
                    <?php foreach($sharers as $key => $value): ?>
                        <li><a href="<?php echo base_url('user/shared/view/'.$value['shared_owner_id']) ?>"><?php echo $value['owner_first_name']." ".$value['owner_last_name'] ?></a></li>
                    <?php endforeach; ?>
                </ul>
            </div>

Model:

class Shared_model extends crud_model {

    public function __construct()
    {
        parent::__construct();

        $this->pk = 'id';
        $this->table_name = 'shared';
    }

    public function get($shared_to_user_id)
    {
        $this->db->where('shared_to_id', $shared_to_user_id);
        $ids = parent::get_all();

        $users = array();

        foreach ($ids as $id)
        {

            $users[] = $id->owner_id;
        }

        return $users;
    }
}

Thank you so much for your help, and let me know if there is any more information that may be required. Below are the original view and controllers that work, but are not preferable.

Original Controller:

public function index()
    {

            $title['title'] = 'Shared';

            $this->load->model('shared_model','shared');

            $data['sharers'] = $this->shared->get($this->end_user->id);

            $this->load->view('user/head_view', $title);
            $this->load->view('user/header_view');
            $this->load->view('user/navigation_view');
            $this->load->view('user/shared_view', $data);
            $this->load->view('user/footer_view');
    }

Original View:

<?php foreach($sharers as $s): ?>
    <li><a href="<?php echo base_url('user/shared/mobile/'.$s) ?>"><?php echo $s ?></a></li>
<?php endforeach; ?>

Disclaimer: I’m new to web development, and I suck at associative arrays (apparently).

  • 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-27T21:04:18+00:00Added an answer on May 27, 2026 at 9:04 pm

    I’ve figured it out. I needed to create an associative array in my model; not my controller. Thanks to everyone for your help!

    Model:

    class Shares_model extends crud_model {
    
        public function __construct()
        {
            parent::__construct();
    
            $this->pk = 'id';
            $this->table_name = 'shares';
        }
    
        public function get($shared_to_user_id)
        {
            $this->db->where('shared_to_id', $shared_to_user_id);
            $ids = parent::get_all();
    
            $users = array();
    
            foreach ($ids as $id)
            {
                $users[$id->owner_id]['owner_id'] = $id->owner_id;
                $users[$id->owner_id]['owner_first_name'] = $id->owner_first_name;
                $users[$id->owner_id]['owner_last_name'] = $id->owner_last_name;
            }
    
            return $users;
        }   
    }
    

    View:

    <ul>
        <?php foreach($sharers as $s): ?>
            <li><a href="<?php echo base_url('user/shared/view/'.$s['owner_id']) ?>"><?php echo $s['owner_first_name']." ".$s['owner_last_name'] ?></a></li>
        <?php endforeach; ?>
    </ul>
    

    Controller:

    public function index()
        {
            $title['title'] = 'Shared';
    
            $this->load->model('shares_model','shares');
    
            $data['sharers'] = $this->shares->get($this->end_user->id);
    
            $this->load->view('public/head_view', $title);
            $this->load->view('user/header_view');
            $this->load->view('user/shared_view', $data);
            $this->load->view('user/footer_view');
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to UITableView issue when using separate delegate/dataSource , though I
We have an issue with some deadlock and I posted this question . With
In this question the issue of using dates in data.table s was discussed. A
I saw many question addressing this issue but still i have some doubts... I
I have a MultiThreading issue and conceptual question using Visual Basic (but it applies
I basically have the same issue as this question: Embed multiple icons in WPF
(EDIT: This question is now outdated for my particular issue, as Google Code supports
Ok this is a general question about how to solve this issue, not to
This question follows on from a previous question, that has raised a further issue.
(Jeopardy-style question, I wish the answer had been online when I had this issue)

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.