I have this site http://mxcounters.com/traffictack/
Users come to site register and logged in. After login they search their domain for some seo reviews. Now all I want to store the each user search into database separately. Then I will show the searched domain by each user to their account page.
I have tried some last activity method to store in database but it is not as much useful please help me on this:
$time_since = now() - $this->session->userdata('last_activity');
$interval = 300;
// Do nothing if last activity is recent
if ($time_since < $interval) return;
// Update database
$updated = $this->db
->set('last_activity', now())
->where('id', $user_id)
->update('users');
2
Answers
If you want to insert each search you can use:
First create a table in which the records are stored.
In this table the timestamp is automaticly added to the entries.
then use a insert query on each search:
If you only want to update the last_activity column:
Alter your table that after every table update the last_activity is updated and use a second column e.g. named searchString to contain the last searched item.
Then use a query on each search:
Please use right escaping when using databases (PDO prepared statements are a good option)
Try this
In conteroller
In Model