Welcome Guest, Not a member yet? Register   Sign In
Update Only Recent Row in Table
#1

[eluser]glenconde[/eluser]
A little help here igniters, i can't get how to update only one most recent row in my table to update it.. it is working, but when I logout to the system, all the table rows will update too, based on the logout time..
here's my code:

Code:
function logout()
{
  $this->db->get('employee_logs');
  $this->db->order_by("person_id","timestamp","desc",$limit=1);
  $person_id = $this->session->userdata('person_id');
  $this->session->sess_destroy();
  
  $data = array (

  'logout_time' =>date('H:i:s')

  );


//  $this->db->where('person_id', $person_id);
  $this->db->update('employee_logs', $data);
  
  redirect('login');
}

Thank's in advance!
#2

[eluser]Aken[/eluser]
That's because you've commented out the part that narrows down the update to one specific person_id. Instead you're just updating the entire table.
#3

[eluser]glenconde[/eluser]
I can now update each person separately, the only thing is when the person login and logout, it updates all of his lougout time.. ive filtered the person_id, now my problem is how to update only current/recent row in each person_id?

This is my Code now:

Code:
function logout()
{
  $this->db->get('employee_logs');
  $this->db->order_by("person_id", "desc", $limit=1);
  $person_id = $this->session->userdata('person_id');
  $this->session->sess_destroy();
  
  $data = array (

  'logout_time' =>date('H:i:s')

  );

  $this->db->update('employee_logs', $data, "person_id = $person_id");
  
  redirect('login');
}
#4

[eluser]Aken[/eluser]
You need to explain in more detail how your table is structured, and what would justify a row as being current or most recent.
#5

[eluser]glenconde[/eluser]
Thank's for the reply sir..

Here's my table structure:

Field Type Collation Attributes Null Default Extra Action
person_id int(10) No
login_time time No
logout_time time No
date date No

------------

when I login, it inserts the person_id, login_time and date.. and the logout_time in the table put's up
00:00:00..

then, i want to UPDATE the table where person_id login, and update it's logout_time where the logout_time=00:00:00..
but my main problem here is that when I logout, all of the same person_id will be updated too..

here is the Result:

person_id login_time logout_time date

1 19:09:20 19:17:30 2012-03-06
1 19:16:43 19:17:30 2012-03-06
1 19:17:27 19:17:30 2012-03-06




Theme © iAndrew 2016 - Forum software by © MyBB