The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need a point in the right direction
#1
Well I'm back, and having a hell of a time figuring out what I'm doing haha. My inexperience with PHP is showing and I have no idea how to get what I want done...done. I haven't coded with this stuff in 5-6 years so I'm quite out of touch.

Basically, I'm just looking for some help on getting a single function done. Once I figure that out, I'm confident I can take it from there and run with it. I just need help with the basics to get me started.

So for one, I need to add another row/column (I think?) to your database where I can log times when a button is pressed. I have no idea how to do that, but I plan on trying in phpMyAdmin to see how that works out. Problem is I don't know what options to use...I just know that I need to be able to store timestamps in it.

Second, I don't know what an example code would look like to set that timestamp into the DB for that relevant user. I've tried Google and my other team member tried coding something from scratch himself and we both are failing to figure out how to keep any DB entries made by a user stuck to that user's session.

I'm trying to make something like a time clock but not really...it will evolve into tracking breaks of team members as a whole, showing realtime who is on break and for how long they've been on break, give reports to myself and the other supervisor about often people are up out of their desks, etc.
  Reply
#2
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.


  Reply
#3
I will try it as soon as I get into the office! I think that my be exactly what I'm looking for, and wow on your phone? You sir are a scholar. I almost even refuse to answer an email on my phone haha.
  Reply
#4
Haha... I am in a good mood and had a little extra time on my hands..., one tip is that you definitely have to make sure that your time is formatted the same as in the database and you might have to run some kind of little conversion. If not, it will just show up with all zeros in the database. It's pretty easy to Google formatting date and time in PHP if you get stuck there.
  Reply
#5
Yeeeeaaaaah...I guess I should stop using date.(DATE_RFC2822) then lol. I meant to get to this today but shit hit the fan at work today >_< I'll update tomorrow after testing...hopefully I can make this work lol.
  Reply
#6
This makes me laugh because I remember when I was helping my friend do an assignment for his programming class I was typing our MySQL queries using JOIN and WHERE and oh it was just a disaster but he passed his project!

Anyways, spinoff on this...what file would I modify to make it so every time a user visits a page, it submits to the DB user visited
Code:
$pagetitle
. I can figure out everything else, just need to know where to put this at.

Thanks!
  Reply
#7
The thing you would have to worry about is what happens if the user is not logged in or a real user. I would probably modify the secure page function with an if statement... then you just have to be careful when updating
  Reply
#8
It hates me -

Parse error: syntax error, unexpected '=', expecting ')' in /home/randomserverlocation/index.php on line 49

//set check-in function
function checkIn()
{
$timein = date('H:i');
echo 'Your check-in time is '.$timein.'.';
$chkfields=array(
'user_id' = $user-data()->id, //LINE 49
'click' = $timein,
);
$db->insert('clicks', $chkfields);
}



^ This array isn't working Sad
I have the requires at the top, init, header, and navigation with the securePage thing...so that's all there.Did I miss a ; or ' and just can't see it? My other array is working fine and displaying as it should, and looks close enough to the other one to me lol.

//generate buttons
function get_buttons()
{
$str='';
$btns=array(

1=>'Check In',
2=>'Go on Break',
3=>'Go on Lunch',
4=>'Return from Break or Lunch',
);

while(list($k,$v)=each($btns))

{
$str.=' <input class="btn btn-info" type="submit" value="'.$v.'" name="btn_'.$k.'" id="btn_'.$k.'"/>';
}
return $str;
}




^ This array works perfect.
  Reply
#9
nvm on that part...think I finally got it figured out. Changed = to => and error went away. Now it behaves until I click the button, where I get "call to undefined function data()" instead. I guess I should poke around on that instead now...
  Reply
#10
It's ugly, but it's working haha

//set check-in function
function checkIn()
{
$timein = date('H:i');
echo 'Your check-in time is '.$timein.'.';
$chkfields=array(
'id' => $logged_in->id,
// 'username' => $logged_in->username, <-- Can't get this working for some reason though
'timein' => $timein,
);

$db = DB::getInstance();
$db->insert('clicks', $chkfields);
}

root@training [/home/randomserverpathhere/]# mysql somedbhere -e 'select * from clicks;'
+----+----------+--------+
| id | username | timein |
+----+----------+--------+
| 4 | | 21:35 |
+----+----------+--------+
root@training [/home/somepathhere]# mysql somedbhere -e 'describe clicks;;'
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(255) | NO | | NULL | |
| timein | varchar(255) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+

Unfortunately I can't figure out the datetime/timestamp issue between PHP and the DB just yet...but I have made real progress now lol. Just had to dig around the user class docs a bit and watch the db class videos to understand why it wasn't working.
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)