Reputation: 395
I would like to configure an SQL query where it would not insert again if the record exists.
Thanks in advance.
$name="John";
$value="login";
$this->db->query(
$this->db->insert_string("user_log", array(
"user_log_user_id" => $this->session->userdata("user_id"),
"user_log_name" => $name,
"user_log_value" => $value,
"user_log_date" => time()
))
If it has the same time and the same activity , it should not be inserted into the log information table.
Eg.
CURRENT ISSUE:
No User Activity Time
-- ---------- ---------- ----------
1 John Login 01/10/2014 10:55
2 John Login 01/10/2014 10:55
3 John Login 01/10/2014 10:55
4 John Logout 01/10/2014 11:00
5 John Logout 01/10/2014 11:00
EXPECTED RESULT:
No User Activity Time
-- ---------- ---------- ----------
1 John Login 01/10/2014 10:55
2 John Logout 01/10/2014 11:00
Upvotes: 1
Views: 1471
Reputation: 7675
You need to use "ON DUPLICATE KEY UPDATE". The following link will help you a lot I think
https://ellislab.com/forums/viewthread/203637/
Upvotes: 1