1
jmass
Change user id to username in array for Smarty
  • 2004/2/18 21:33

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


I have and array of arrays that are pulled from a MySQL table to pass to a Smarty section:

function chooseUpdateFields( $TicketID )
{

global $xoopsDB;
$ret = array();

$sql = "SELECT UID, EntryDate, UpdateDetails FROM ".$xoopsDB->prefix("obsclient_hd_ticketupdate")." WHERE ParentTicketID = ".$TicketID;

$result_choose = $xoopsDB->query($sql);

while ( $client_row = $xoopsDB->fetchArray($result_choose) )

{
$ret[] = array('UID' => $client_row['UID'], 'EntryDate' => $client_row['EntryDate'], 'UpdateDetails' => $client_row['UpdateDetails']);

}
return $ret;

}

The problem is that it passes the user id and I want to display the username. Any thoughts?

JMass

2
tl
Re: Change user id to username in array for Smarty
  • 2004/2/18 21:51

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


No information on your obsclient_hd_ticketupdate table structure. Likely you would have to do a joint-query on the user table to pull out the username.

BTW, "technically declined?" No, you are doing great.

3
jmass
Re: Change user id to username in array for Smarty
  • 2004/2/18 22:10

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


Here is the table structure:

# Table structure for table `obsclient_hd_ticketupdate`

#

CREATE TABLE obsclient_hd_ticketupdate (

TicketUpdateID int(10) NOT NULL auto_increment,
ParentTicketID int(10) NOT NULL default '0',
UID int(10) NOT NULL default '0',
EntryDate date NOT NULL default '0000-00-00',
UpdateDetails text NOT NULL default '',

PRIMARY KEY (TicketUpdateID)

) TYPE=MyISAM;
#
# Table structure for table `obsclient_hd_ticketdata`

#

CREATE TABLE obsclient_hd_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',

PriorityID int(10) NOT NULL default '0',

EntryDate date NOT NULL default '0000-00-00',
TicketSubject varchar(255) NOT NULL default '',

TicketDetails text NOT NULL default '',

PRIMARY KEY (TicketID)

) TYPE=MyISAM;
#

The ParentTicketID from obsclient_hd_ticketupdate is the TicketID from obsclient_hd_ticketdata.

UID in both cases is the user entering the data.

Thanks for the encouragement,

JMass

4
tl
Re: Change user id to username in array for Smarty
  • 2004/2/18 22:48

  • tl

  • Friend of XOOPS

  • Posts: 999

  • Since: 2002/6/23


You would definitely need to do a joint-query on both obsclient_hd_ticketupdate and user table to pull out the username.

Good luck. It seems to be a nice of ticketing system you are developing.


5
jmass
Re: Change user id to username in array for Smarty
  • 2004/2/19 3:50

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


Thanks for the direction to look. If anyone has some example of a joint-query, that would be great.

Yes it is a Help Desk type Ticketing system.

Thanks,

JMass

6
Dave_L
Re: Change user id to username in array for Smarty
  • 2004/2/19 4:15

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Something like this:

$ticket_table $xoopsDB->prefix('obsclient_hd_ticketupdate');
$users_table  $xoopsDB->prefix('users');

$result_choose $xoopsDB->query(
   
"SELECT u.uname, t.EntryDate, t.UpdateDetails FROM $ticket_table AS t
   LEFT JOIN 
$users_table AS u ON u.uid = t.UID
   WHERE t.ParentTicketID = 
$TicketID
"
);

7
jmass
Re: Change user id to username in array for Smarty
  • 2004/2/19 4:35

  • jmass

  • Friend of XOOPS

  • Posts: 524

  • Since: 2003/12/18


Perfect!

I am very new to "Black Magic" of Table Joins. I am always amazed how you guys whip out great code like that. I can modify existing code to meat my needs very well, but the from scratch stuff takes me forever.

This is my final code that is implemented and working:

function chooseUpdateFields( $TicketID )
{

global $xoopsDB;
$ret = array();
$ticket_table = $xoopsDB->prefix('obsclient_hd_ticketupdate');
$users_table = $xoopsDB->prefix('users');

$sql = "SELECT u.uname, t.EntryDate, t.UpdateDetails FROM $ticket_table AS t LEFT JOIN $users_table AS u ON u.uid = t.UID WHERE t.ParentTicketID = $TicketID";

$result_choose = $xoopsDB->query($sql);

while ( $client_row = $xoopsDB->fetchArray($result_choose) )

{
$ret[] = array('UNAME' => $client_row['uname'], 'EntryDate' => $client_row['EntryDate'], 'UpdateDetails' => $client_row['UpdateDetails']);

}
return $ret;
}

Thanks again for the great code,

JMass

8
Dave_L
Re: Change user id to username in array for Smarty
  • 2004/2/19 5:12

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Quote:
I am very new to "Black Magic" of Table Joins. I am always amazed how you guys whip out great code like that. I can modify existing code to meat my needs very well, but the from scratch stuff takes me forever.


Just spend a few months writing PHP/MySQL stuff, and you'll pick it up.

Login

Who's Online

87 user(s) are online (50 user(s) are browsing Support Forums)


Members: 0


Guests: 87


more...

Donat-O-Meter

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

Latest GitHub Commits