loadObject(); //echo $queryN; echo $rowN->name;?> ThanksAmal"> Showing username who modified record - Forums

Forums

Showing username who modified record

amsharma 06 Feb, 2014
Hello,

I need to show the UserName of the user who last modified a record. I had a look at this post
http://chronoengine.com/forums/posts/f12/t12163

My requirement is slightly different I need to show the name in an output with other data. I know the user id who modified from the field "cf_modified_by" whihch is stored in the table but how do I get the name. Do I have to query the table for each record in the body code. I have written the below code in "body". It doesn't work. Let me know if this is the right way to do it. The SQL seems to be ok. Does Joomla have some function to get username or name from userid.
<tr>
      <td style="font-weight: bold; color: gray;width: 5%;"><?php global $ll_count; echo $ll_count++; ?></td>
      <td style="width: 15%;"><strong>{ip_text_first_name}</strong></td>
      <td style="width: 15%;"><strong>{ip_text_last_name}</strong></td>
      <td style="width: 5%; text-align:right;">{cf_modified_by},
<?php
  $db =& JFactory::getDBO();
  $queryN = "SELECT id, name, username FROM `jos_users` WHERE `id` = '{cf_modified_by}'";
  $db->setQuery($queryN);
  $rowN = $db->loadObject();
  //echo $queryN;
  echo $rowN->name;
?> 
</td>
</tr>


Thanks
Amal
GreyHead 06 Feb, 2014
Hi amsharma,

Please see this FAQ and go to the section about Other Users.

Bob
amsharma 07 Feb, 2014
GreyHead,

I tried many options but it doesn't seem to work. The code from FAQ always returns the currently logged in user and not the user from the row in the result.

I tried using '{cf_modified_by}', {cf_modified_by}, `{cf_modified_by}`, $form->data[cf_modified_by] as an arugment to getUser() but none of them worked. I tried get the name but some of them work and others return blank.
Below code returns the correct UserId for each row:
$ll_userid = '{cf_modified_by}';
echo $ll_userid ;


But adding
$user =& JFactory::getUser($ll_userid);
echo $user->username;


Gives "JUser: :_load: User {cf_modified_by} does not exist" for each row. I tried using the other quote and then the error goes away but I never the actual username or name. It only gave the current logged in user.

Also wanted to know which one of the following should work:
1. $user =& JFactory::getUser(`{cf_modified_by}`);
2. $user =& JFactory::getUser('{cf_modified_by}');
3. $user =& JFactory::getUser({cf_modified_by});
4. $user =& JFactory::getUser($form->data[cf_modified_by]);

My knowledge of Php is average so pls don't mind my asking all this. Are the fields in braces replaced in all php code, whether in single, double quote etc.

Regards
Amal
GreyHead 08 Feb, 2014
HI Amal,

You usually can't mix the ChronoForms {input_name} with PHP - I'm surprised that it did anything useful in your example.

I think you something like this:
<?php
$user =& JFactory::getUser($row->cf_modified_by);
echo $user->username;
?> 

Bob
amsharma 09 Feb, 2014
GreyHead,

Thanks for replying on the weekend. Sorry it doesn't seem to work. Only gives the logged in user for each row. My guess is that the issue is with JFactory::getUser(). Checked the documentation http://docs.joomla.org/JFactory/getUser, it says it accepts an argument. Not sure what is going on.

Thanks
Amal
vales 09 Feb, 2014
Create a new model with

table name:users
model: you_model
relations: Belong to
foreign key: user_id
fields: username

in front list -> coloumns list add

you_model.username: Username
vales 09 Feb, 2014
The previous post is for chronoconenctivity v5.

But is similar to chonoconnectivity v4. Change foreign key with created_id
GreyHead 09 Feb, 2014
Hi Amal,

Please try the same code but replace $row->cf_modified_by with $row['cf_modified_by'] Max changes the way the data is shown between versions :-( I copied the object method from another post of his but it may not work with the version of CC that you have.

If that doesn't work then you'd need to turn on the CC Debugger to see what data is available.

As you say the JFactory::getUser() method accepts parameter - from memory either a user ID or a username.

Bob
amsharma 09 Feb, 2014
Answer
GreyHead,

$row['cf_modified_by'] worked. Thanks a lot. FYI I had used the debugger all this time and it was showing the correct data for each row all this time, i.e. correct cf_modified_by.

Amal
This topic is locked and no more replies can be posted.