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

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

Postby maw2be » Mon Dec 21, 2015 10:24 pm

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?
maw2be
 
Posts: 6
Joined: Mon Dec 21, 2015 10:13 pm

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

Postby admin » Tue Dec 22, 2015 7:49 am

maw2be,

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

Steven
admin
Site Admin
 
Posts: 3079
Joined: Mon Jun 15, 2009 9:53 am

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

Postby maw2be » Sat Jan 09, 2016 2:39 am

thanks
but i need to see who create "row" so I create table USER and compare USER to #nu_user_name#
maw2be
 
Posts: 6
Joined: Mon Dec 21, 2015 10:13 pm

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

Postby admin » Mon Jan 11, 2016 3:06 pm

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 9176 times


Steven
admin
Site Admin
 
Posts: 3079
Joined: Mon Jun 15, 2009 9:53 am

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

Postby maw2be » Sat Jan 23, 2016 1:23 am

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
maw2be
 
Posts: 6
Joined: Mon Dec 21, 2015 10:13 pm

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

Postby Ion2 » Tue Jan 26, 2016 6:36 pm

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
Ion2
 
Posts: 41
Joined: Mon Jan 18, 2016 11:31 pm

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

Postby admin » Fri Feb 12, 2016 10:33 am

maw2be,

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

Steven
admin
Site Admin
 
Posts: 3079
Joined: Mon Jun 15, 2009 9:53 am

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

Postby pyro » Thu Jan 18, 2018 8:37 pm

Hi,

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

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


Any ideas why it does not work
pyro
 
Posts: 11
Joined: Thu Jan 18, 2018 3:36 am

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

Postby pyro » Thu Jan 18, 2018 8:52 pm

never mind changed in version 4 viewtopic.php?f=19&t=9189
pyro
 
Posts: 11
Joined: Thu Jan 18, 2018 3:36 am


Return to General



cron