Page 1 of 1

How to put current user into table (to see who create record

PostPosted: Mon Dec 21, 2015 10:24 pm
by maw2be
I need to put into table column with user, to see who create record and thanks to this user can see only "his" cases. As for me php, sql and rest is something new so I ask.
can you help me how to put into field/object administrator details of user who create it?

Re: How to put current user into table (to see who create re

PostPosted: Tue Dec 22, 2015 7:49 am
by admin
maw2be,

Adding certain fields to a table will automatically record user information.. http://wiki.nubuilder.net/nubuilderv3/index.php/Forms#Save_Button

Steven

Re: How to put current user into table (to see who create re

PostPosted: Sat Jan 09, 2016 2:39 am
by maw2be
thanks
but i need to see who create "row" so I create table USER and compare USER to #nu_user_name#

Re: How to put current user into table (to see who create re

PostPosted: Mon Jan 11, 2016 3:06 pm
by admin
maw2be,

You could try something like this.

Code: Select all
$s = "
    UPDATE toy
    SET toy_user_id = '#nu_user_name#'
    WHERE toy_user_id = ''

";

nuRunQuery($s);


And put it here..

Capture1.PNG
Capture1.PNG (17.49 KiB) Viewed 10127 times


Steven

Re: How to put current user into table (to see who create re

PostPosted: Sat Jan 23, 2016 1:23 am
by maw2be
Thanks
Can you expand this littlebit?
I thinking about make additional column "modified by" where I will see who and when last time save this. can you help? With insert into SQL should be ok, problem is with searching last position so i can see who was last one.

admin wrote:maw2be,

You could try something like this.

Code: Select all
$s = "
    UPDATE toy
    SET toy_user_id = '#nu_user_name#'
    WHERE toy_user_id = ''

";

nuRunQuery($s);


And put it here..

Capture1.PNG


Steven

Re: How to put current user into table (to see who create re

PostPosted: Tue Jan 26, 2016 6:36 pm
by Ion2
Dear maw2be,

let's support each other, as mentioned previously by Steven, the Save Button fulfills your demand of logging who last modified the data set.

You need to add the following to your table:

Code: Select all
ALTER TABLE ?? 
ADD ??_log_added_at DATETIME NOT NULL, 
ADD ??_log_added_by VARCHAR(25) NOT NULL,
ADD ??_log_changed_at DATETIME NOT NULL, 
ADD ??_log_changed_by VARCHAR(25) NOT NULL,
ADD ??_log_viewed_at DATETIME NOT NULL, 
ADD ??_log_viewed_by VARCHAR(25) NOT NULL

Replace ?? with the name of your table.

Source: http://wiki.nubuilder.net/nubuilderv3/index.php/Forms#Save_Button


It automaticly adds the zzzsys_user_id from the zzzsys_user table to the ??_log_xyz_by fields above, and works very fine for me. Than you need to make an inner join to the zzzsys_user table to get the real names.

I'm still struggling with the inner join. Help very much appreciated.

You'll find my post to this topic here: http://forums.nubuilder.com/viewtopic.php?f=13&t=8866

Greetings,
Timo

Re: How to put current user into table (to see who create re

PostPosted: Fri Feb 12, 2016 10:33 am
by admin
maw2be,

Timo's answer is the better way to do it.

Steven

Re: How to put current user into table (to see who create re

PostPosted: Thu Jan 18, 2018 8:37 pm
by pyro
Hi,

I tried to follow the instruction however the system does not automatically fill the information:

phpmyadmin.PNG
phpmyadmin.PNG (342.89 KiB) Viewed 6475 times


Any ideas why it does not work

Re: How to put current user into table (to see who create re

PostPosted: Thu Jan 18, 2018 8:52 pm
by pyro
never mind changed in version 4 viewtopic.php?f=19&t=9189