Jump to content

Showing Data Assigned to User


Moorcam
Go to solution Solved by Moorcam,

Recommended Posts

So, when a user logs in, I would like to grab data from the db and display it based on their id, which is in a session.

Here is my Controller:

public function jobs()
    {
        if($this->session->userdata('e_id')){
            $id = $this->session->userdata('e_id');
            $data['tour'] = $this->usermodel->job($id);
            $this->load->view('tour',$data);
        }else{
            echo "No results";

        }

    }

Here is my Model:

public function job($id) {
    $this->db->select('*')
             ->from('tbl_tour')
             ->where('e_id', $id);
    return $this->db->get()->result();
}

And finally, View:

<table class="table table-striped">
    <tr>
        <th>Date</th>
        <th>Tour</th>
    </tr>
        <?php
            foreach($tour as $job):?>
    <tr>
        <td><?php echo $job->start_date;?></td>
        <td><?php echo $job->name;?></td>
    </tr>
        <?php endforeach;?>
</table>

When executing I get Undefined variable: tour

And also:

Message: Invalid argument supplied for foreach()

If anyone can help with this it would be appreciated.

Link to comment
Share on other sites

Hi mate,

 

Sorry. Made a few changes but the above was the culprit really. Here is the full update.

Controller:

	public function index()
	{
		$data['setting'] = $this->Model_common->get_setting_data();
		
		$data['tour'] = $this->Model_dashboard->all_tour('p_id');
	

		$data['total_category'] = $this->Model_dashboard->show_total_category();
		$data['total_news'] = $this->Model_dashboard->show_total_news();
		$data['total_motel'] = $this->Model_dashboard->show_total_motel();
		$data['total_tour'] = $this->Model_dashboard->show_total_tour();
		$data['total_team_member'] = $this->Model_dashboard->show_total_team_member();
		$data['total_agent'] = $this->Model_dashboard->show_total_agent();
		$data['total_service'] = $this->Model_dashboard->show_total_service();
		$data['total_testimonial'] = $this->Model_dashboard->show_total_testimonial();
		$data['total_traveller'] = $this->Model_dashboard->show_total_traveller();
		$data['amount_paid'] = $this->Model_dashboard->show_amount_paid();
		$data['total_fleet'] = $this->Model_dashboard->show_total_fleet();
		$data['total_driver'] = $this->Model_dashboard->show_total_driver();
		


		$this->load->view('admin/view_header',$data);
		$this->load->view('admin/view_dashboard',$data);
		$this->load->view('admin/view_footer');
	}

Model:

    public function all_tour()
    {
		$e_id = $this->session->userdata('e_id');
        $query = $this->db->query("SELECT * FROM tbl_tour WHERE e_id = $e_id ORDER BY p_id ASC");
        return $query->result_array();
    }

View:

<table class="table table-striped">
    <tr>
        <th>Tour</th>
		<th>Departure Date</th>
		<th>Return Date</th>
		<th>Fleet Number</th>
        
    </tr>
        <?php
            foreach($tour as $row):?>
    <tr>
        <td><?php echo $row['p_name']; ?></td>
		<td><?php echo $row['p_start_date']; ?></td>
		<td><?php echo $row['p_end_date']; ?></td>	
		<td><?php echo $row['v_number']; ?></td>
    </tr>
        <?php endforeach;?>
</table>

 

Edited by Moorcam
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.