Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

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

Post Reply
maw2be
Posts: 6
Joined: Mon Dec 21, 2015 1:43 pm

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

Unread post 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?
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

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

Unread post by admin »

maw2be,

Adding certain fields to a table will automatically record user information.. http://wiki.nubuilder.net/nubuilderv3/i ... ave_Button

Steven
maw2be
Posts: 6
Joined: Mon Dec 21, 2015 1:43 pm

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

Unread post by maw2be »

thanks
but i need to see who create "row" so I create table USER and compare USER to #nu_user_name#
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

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

Unread post 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 18187 times
Steven
maw2be
Posts: 6
Joined: Mon Dec 21, 2015 1:43 pm

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

Unread post 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
Ion2
Posts: 41
Joined: Mon Jan 18, 2016 3:01 pm

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

Unread post 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/i ... ave_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.cloud/viewtopic.php?f=13&t=8866

Greetings,
Timo
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

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

Unread post by admin »

maw2be,

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

Steven
pyro
Posts: 11
Joined: Wed Jan 17, 2018 7:06 pm

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

Unread post 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 14535 times
Any ideas why it does not work
pyro
Posts: 11
Joined: Wed Jan 17, 2018 7:06 pm

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

Unread post by pyro »

Post Reply