11-18-2016, 06:33 PM
Don't fret. You have to make 2 decisions before going forward.
1. Do you want to use datetime or timestamp (totally your call).
2. Do you want a log of the LAST time someone clicked the button or EVERY time someone clicked the button.
A. If the last, add a column to the user table maybe called last_cluck that is formatted datetime or timestamp then when the button is clicked...
If clicked statement...
$stamp = whatever you use for timestamp;
$fields =array(
'last_click' = $stamp,
) ;
$db->update('users', $user-data()->id, $fields);
B. If you want a log of every time the button is clicked then I suggest you make a new table maybe called clicks with an auto increment ID, user id, and datetime /timestamp column.
Then everytime someone clicks the button, add a new row.
$stamp = whatever you use for timestamp;
$fields =array(
'user_id' = $user-data()->id,
'click' = $stamp,
) ;
$db->insert('clicks', $fields);
Then you can just do a query...
$clicksQ = $db->query("select * from clicks where user_id = ?", array(user->data()->id));
$clicks = $clicksQ->results();
$count = $clicksQ->count();
Sorry if there are any typos. I am on my phone which is not ideal for coding.
1. Do you want to use datetime or timestamp (totally your call).
2. Do you want a log of the LAST time someone clicked the button or EVERY time someone clicked the button.
A. If the last, add a column to the user table maybe called last_cluck that is formatted datetime or timestamp then when the button is clicked...
If clicked statement...
$stamp = whatever you use for timestamp;
$fields =array(
'last_click' = $stamp,
) ;
$db->update('users', $user-data()->id, $fields);
B. If you want a log of every time the button is clicked then I suggest you make a new table maybe called clicks with an auto increment ID, user id, and datetime /timestamp column.
Then everytime someone clicks the button, add a new row.
$stamp = whatever you use for timestamp;
$fields =array(
'user_id' = $user-data()->id,
'click' = $stamp,
) ;
$db->insert('clicks', $fields);
Then you can just do a query...
$clicksQ = $db->query("select * from clicks where user_id = ?", array(user->data()->id));
$clicks = $clicksQ->results();
$count = $clicksQ->count();
Sorry if there are any typos. I am on my phone which is not ideal for coding.