zzsys_user
Posted: Tue Aug 09, 2011 12:46 pm
Hi there,
Hopefully someone can help me out here.
I'm trying to populate the primary key of a field with a concatenation of a number generated through next_number and the username of the user. The reason I want to do this is that I will likely be running different instances of my site locally at different machines. I will at some point have to merge the different databases, so I want to ensure all primary keys are unique across different sites. Using unique usernames and generating PKs on the basis of these usernames (e.g. Jones1234) should allow me to do this.
I've seen a number of ways to retrieve the user_id for the current user. The Javascript function zzsys_user_id() returns the PK of the current user, and I can use this to populate a field through JavaScript as kindly pointed out by FBCTim in another thread.
current_user = zzsys_user_id();
$('#issue_owner#').val(current_user);
This works alright, but as expected, returns the PK for user_id. What I'm after is the username (zzsys_user.sus_name), and I've been unable to retrieve this using javascript.
What I can do, is use php (in the edit code section of the form) using $this_zzsys_user_id
$id = $this->zzsys_user_id;
$t = nuRunQuery("SELECT zzsys_user.sus_name FROM zzsys_user WHERE zzsys_user_id = '$id'");
$r = db_fetch_row($t);
$current_user = $r[0];
nuDebug($current_user);
Returns the username for the current user (provided the current user is not Globeadmin, as that user isn't in the zzsys_user table). What I've not been able to do is to use that php variable to populate the issue_owner field and I'm stuck as to how I should do this. I tried various ways of sticking the php variable into the default SQL value in the text area for the field but can't seem to populate it. Somehow it seems as if the SQL statement doesn't accept a php variable. I've also tried sticking
SELECT zzsys_user.sus_name FROM zzsys_user WHERE zzsys_user_id = '#zzsys_user_id#'
directly into the default SQL value, but the field remains blank, even when logged in as another user (i.e. not Globeadmin).
I'm sure this should be pretty simple, but being unfamiliar with php or JavaScript and the different types of variables, I've already spent far too long trying to figure this out, so hopefully someone can help me out here.
Cheers,
Dan
Hopefully someone can help me out here.
I'm trying to populate the primary key of a field with a concatenation of a number generated through next_number and the username of the user. The reason I want to do this is that I will likely be running different instances of my site locally at different machines. I will at some point have to merge the different databases, so I want to ensure all primary keys are unique across different sites. Using unique usernames and generating PKs on the basis of these usernames (e.g. Jones1234) should allow me to do this.
I've seen a number of ways to retrieve the user_id for the current user. The Javascript function zzsys_user_id() returns the PK of the current user, and I can use this to populate a field through JavaScript as kindly pointed out by FBCTim in another thread.
current_user = zzsys_user_id();
$('#issue_owner#').val(current_user);
This works alright, but as expected, returns the PK for user_id. What I'm after is the username (zzsys_user.sus_name), and I've been unable to retrieve this using javascript.
What I can do, is use php (in the edit code section of the form) using $this_zzsys_user_id
$id = $this->zzsys_user_id;
$t = nuRunQuery("SELECT zzsys_user.sus_name FROM zzsys_user WHERE zzsys_user_id = '$id'");
$r = db_fetch_row($t);
$current_user = $r[0];
nuDebug($current_user);
Returns the username for the current user (provided the current user is not Globeadmin, as that user isn't in the zzsys_user table). What I've not been able to do is to use that php variable to populate the issue_owner field and I'm stuck as to how I should do this. I tried various ways of sticking the php variable into the default SQL value in the text area for the field but can't seem to populate it. Somehow it seems as if the SQL statement doesn't accept a php variable. I've also tried sticking
SELECT zzsys_user.sus_name FROM zzsys_user WHERE zzsys_user_id = '#zzsys_user_id#'
directly into the default SQL value, but the field remains blank, even when logged in as another user (i.e. not Globeadmin).
I'm sure this should be pretty simple, but being unfamiliar with php or JavaScript and the different types of variables, I've already spent far too long trying to figure this out, so hopefully someone can help me out here.
Cheers,
Dan