1
jmass
Looking up a username from user id
  • 2004/4/21 17:37

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


Hello!

I am storing user ID in a DB table. I need a way to pull the user name based on this ID. I could do a join with this table and the users table... But is there a simpler way to do this?

If I retrieve the user ID from the table, is there a XOOPS class I can use to retrive the user name?

JMass

2
Mithrandir
Re: Looking up a username from user id

XoopsUser::getUnameFromId($uid);

3
jmass
Re: Looking up a username from user id
  • 2004/4/21 17:45

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


Hmmmm... getUnameFromId.....

That almost makes sense!

Thanks again Mith!


JMass

4
jmass
Re: Looking up a username from user id
  • 2004/4/21 17:48

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


Sorry to be dense, but is this correct?

$TicketUpdateUID = $ticket->getTicketUpdateUID( $TicketID );
$TicketUpdateUname = XoopsUser::getUnameFromId($TicketUpdateUID);

Do I need a particular include?

I know $TicketUpdateUID returns a valid user ID.

JMass

5
Mithrandir
Re: Looking up a username from user id

hmmm - your getTicketUpdateUID function requires the ticketID? Isn't a ticket object identified by the ticketID? (off topic, sorry)

You should not need a particular include, since the XoopsUser class is included in common.php

So yes, it looks correct

6
jmass
Re: Looking up a username from user id
  • 2004/4/21 17:55

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


Off topic not a problem (work great by the way, THANKS!)

Function of ticket object:
--------------------------
function getTicketUpdateUID( $TicketID )
{
global $xoopsDB;
$ret = array();
$query_table = $xoopsDB->prefix('obsclient_tt_ticketdata');
$sql = "SELECT UpdateUID FROM $query_table WHERE TicketID = $TicketID";
$result = $xoopsDB->query($sql);
$myrow = $xoopsDB->fetchArray($result);
$ret = $myrow['UpdateUID'];
if( $ret == "" )
{
$ret = "Unknown";
}
return $ret;
}

Table:
------
#
# Table structure for table `obsclient_tt_ticketdata`
#
CREATE TABLE obsclient_tt_ticketdata (
TicketID int(10) NOT NULL auto_increment,
UID int(10) NOT NULL default '0',
StatusID int(10) NOT NULL default '0',
ClientID int(10) NOT NULL default '0',
CategoryID int(10) NOT NULL default '0',
EntryDate date NOT NULL default '0000-00-00',
TicketHours decimal(10,1) NOT NULL default '0',
TicketDetails text NOT NULL default '',
UpdateDate date NOT NULL default '0000-00-00',
UpdateUID int(10) NOT NULL default '0',
PRIMARY KEY (TicketID)
) TYPE=MyISAM;

As you can see, I am retrieving the ID of the last person to update a particular ticket. Therefore, the ticket ID is needed as it is the primary key of the ticket table, and the only unique identifier of the ticket object.

Make sense? Wrong way to do this?

JMass

Login

Who's Online

202 user(s) are online (95 user(s) are browsing Support Forums)


Members: 0


Guests: 202


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits