I have a mysql query which outputs 6 columns of related data, I’m specifically interested in having the results sorted alphabetically by a certain modified column. The unmodified results from that column look like this:
... | 0001: Some text here |...
... | 0002: Flipped text here |...
... | 0003: About some more text |...
The ‘0001:’ portion should not be displayed. Currently, I have a Perl subroutine which removes that portion from being displayed, but I don’t know how I can get all rows sorted alphabetically based off of that resulting column. What I’m looking for would be:
... | About some more text |...
... | Flipped text here |...
... | Some text here |...
The following is what I’m using to retrieve and display said data, but my understanding of Perl is sorely lacking. I don’t understand how the @$data works, just know that it does. My failed sorting attempt is commented out by the #.
$data = $sth->fetchall_arrayref();
$sth->finish;
foreach $data ( @$data) {
($a, $name, $c, $d, $e, $f) = @$data;
# @$data = sort { "\L$a->out_name([2])" cmp "\L$b->out_name([2])"} @$data;
$Response->Write($a.",".out_name($name).",".$c.",".$d.",".$e.",".$f."<br />");
}
Any help or ideas would be greatly appreciated, thank you.
EDIT: I failed to note, the ‘0001:’ portion may appear as ‘511:’ or ‘85000:’, that number isn’t a constant length. If there’s a way to deal with this condition in Mysql, that would be excellent. It didn’t seem like a possibility in my searches, thus why I was attempting it with Perl.
You can get the database to do the sorting for you: