1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

sort the contents of a record field ...

Discussion in 'Databases' started by pepe_lepew1962, Oct 10, 2011.

  1. #1
    Hello:

    When I call up a specific record, I need to sort the contents of "tblpartmanuf" and replace that field with the sorted information. Lets say the record is:

    tblpartnumber tblpartmanuf
    12544 GFSD

    After I edit some other fields, automatically sort the tblpartmanuf field so that it is:
    12544 DFGS




    $sql="SELECT tblpartnumber, tblpartmanuf FROM tblparts WHERE tblpartnumber ='$frmpartfinder'";
    $result = mysql_query($sql) or die('Error: ' . mysql_error());
     
    pepe_lepew1962, Oct 10, 2011 IP
  2. otshare

    otshare Peon

    Messages:
    70
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i have not seen any SQL function which will do this. But one way to do this is to create your own function. Basically you write the code for your function and call it from your sql. your function accepts the tblpartmanuf and returns the name after sorting. So your SQL query will return values after sorting.

    your SQL should look like this:

    $sql="SELECT tblpartnumber, f_sortmanuf(tblpartmanuf) FROM tblparts WHERE tblpartnumber ='$frmpartfinder'";
     
    otshare, Oct 10, 2011 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    What language are you writing this in? Or are you just executing SQL from the command line?
     
    Rukbat, Oct 14, 2011 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Either process all records once and for all by php script for performance reasons

    OR do string sort in php, again for performance reasons.

    I would advice not to try such operations in mysql, which are anyways not to be done there unless extremely needed.
     
    mastermunj, Oct 15, 2011 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    1) We have no idea whether this is MySQL or some other database.

    2) There's nothing wrong with a little sort function in TSQL - we run queries daily that are composed of tens of thousands of lines of TSQL, with MUCH larger functions. How efficient that is depends on the database. In Access? Forget it. In Oracle or RDB? That's how they're used.
     
    Rukbat, Oct 16, 2011 IP
  6. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #6
    I assumed it to be MySQL from the code written at last in OP.

    
    $sql="SELECT tblpartnumber, tblpartmanuf FROM tblparts WHERE tblpartnumber ='$frmpartfinder'";
    $result = mysql_query($sql) or die('Error: ' . mysql_error());
    
    PHP:
     
    mastermunj, Oct 17, 2011 IP