Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Dec 2007
    Posts
    6
    Member #
    16237
    I've created a transaction_info table with the following columns

    transaction_order
    username_from
    username_to
    date
    amount

    as well as some other columns, but this will suffice for my question. When a user logs in to view their transactions I use the query

    SELECT * FROM transaction_info WHERE username_from='$username' OR username_to='$username' ORDER BY transaction_order DESC;

    I then generate an HTML table with columns

    description
    date
    amount
    new_balance

    the description column is made up of "From " . $row['username_from'] or "To " . $row['username_to'] depending on which one contained the

    username that didn't match $username. I comb through the array with PHP to determine this. But I want the user to be able to click on a sort

    arrow and sort their descriptions alphabetically. Because 'description' is made from two mysql columns, I don't know how to use ORDER BY to

    accomplish this. Instead I've resorted to loading the whole thing into a two-dimensional array, sorting the array, then printing it to the

    HTML table. The code is monstrous. Is there a more direct mysql command that would accomplish the same thing?

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    If I understand you correctly, what you could do is order by 3 columns.

    Something like

    Code:
    SELECT * FROM transaction_info WHERE username_from='$username' OR username_to='$username' 
    ORDER BY transaction_order,username_from,username_to DESC;


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:28 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com