[eluser]Unknown[/eluser]
i am having an issue with displaying results that are specific to a user, like timesheet entries
Controller:
Code:
class Internal extends Controller {
function Internal()
{
parent::Controller();
$this->load->helper('date');
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('entry_model');
session_start();
}
function index()
{
$userlist = $this->session->userdata('username');
$data['entry'] = $this->db->get('entries');
$data['client'] = $this->db->get('clients');
$data['job'] = $this->db->get('jobs');
$data['task'] = $this->db->get('tasks');
$data['entry'] = $this->session->userdata('username');
$data['user_results'] = $this->entry_model->getResults($userlist);
$this->load->view('internal_view', $data);
if ($this->session->userdata('logged_in') != TRUE)
{
redirect('login');
}
}
function time_insert()
{
$this->db->insert('entries', $_POST);
redirect('internal');
}
function time_edit()
{
$this->load->helper('date');
$this->db->where('entryId', $this->uri->segment(3));
$data['entry'] = $this->db->get('entries');
$this->load->view('edit_time_view', $data);
}
function time_update()
{
$this->load->helper('date');
$this->db->where('entryId', $_POST['entryId']);
$this->db->update('entries', $_POST);
redirect('internal');
}
function time_delete($id)
{
$this->db->where('entryId', $id);
$this->db->delete('entries', $this->entries);
redirect('internal');
}
}
Model:
Code:
class Entry_model extends Model {
function Entry_model()
{
parent::Model();
}
function getResults ($userlist, $usertimes = TRUE)
{
$this->db->like('user', $userlist);
$this->db->orderby('e_date');
$query = $this->db->get('entries');
if ($query->num_rows() > 0) {
foreach ($query->result() as $time) {
if ($usertimes) {
$output = '<div class="sumEntry">';
$output .= '<div class="sumDate">' . $time->e_date . '</div>';
$output .= '<div class="sumClient">' . $time->client . '</div>';
$output .= '<div class="sumJob">' . $time->jobNumber . '</div>';
$output .= '<div class="sumTask">' . $time->task . '</div>';
$output .= '<div class="sumHours">' . $time->hours . ':' . $time->minutes .'</div>';
$output .= '<div class="sumEdit">edit entry link</div>';
$output .= '<div class="sumEdit">delete entry link</div>';
$output .= '</div>';
}
}
return $output;
} else {
return '<p>Sorry, no results returned.</p>';
}
}
}
How it is initiated:
The user logs in and the username is held as a session variable, the user then adds their time for the day and the entry appears in the list.
As more entries are added the list gets longer and only shows that users times, other users times will only be viewable by them.
What actually happens:
user logs in and starts adding entries but only the lasts entry appears in the list for that user.
So the login works and the user specific data appears but the foreach loop seems no to be working.
If i remove the model and just use the foreach in the view it works but shows all users data, ideal for an administrator but not for the users.
please if you are able to help i have 2 other projects that could benifit from this solution also.
Many thanks
Mark