Jump to content

Problem with sorting in a query


yrrahxob

Recommended Posts

Ok here is my problem. I have a query where I read a table T1 named

MHI_ISSUES and 9 of the columns in the table contain a user id which

can be from 1 to 3 digits. I also have another tabe T3 named MHI_USERS

that I use to get the user name for each of the columns in the first table

and then display them in a table on the screen. The headers on each

of the columns is a link refreshing the page and sending a sort by number

telling the query to sort by this column. When I do this, it sorts by

the user_id number but I want it to sort by the user name. Does anyone

know of a way to do this? I have my query shown below. Any help

would be greatly appreciated.

 

$qry=\"SELECT t1.issue_id,

t1.issue_name,

t2.status_desc,

t1.user_id,

t1.assigned_to,

t1.assigned_to_orig,

t1.modified_by,

t1.interested_party1_id,

t1.interested_party2_id,

t1.interested_party3_id,

t1.interested_party4_id,

t1.interested_party5_id

FROM

mhi_issues AS t1,

mhi_statuses AS t2,

mhi_users AS t3

WHERE

t1.status_id = t2.status_id AND (

t1.user_id = \'$user\' OR // $user is the 1 to 3 digit user_id number

t1.assigned_to = \'$user\' OR

t1.assigned_to_orig = \'$user\' OR

t1.interested_party1_id = \'$user\' OR

t1.interested_party2_id = \'$user\' OR

t1.interested_party3_id = \'$user\' OR

t1.interested_party4_id = \'$user\' OR

t1.interested_party5_id = \'$user\' OR

t1.modified_by = \'$user\') AND

t3.user_name = \'$user_name\' // $user_name is the user_name field which I get when the page is loaded

ORDER BY $sort_field

LIMIT $seek_pos, $limit_return\";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.