codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Sorting by column on webpage  yesti at 20:13 on Tuesday, February 05, 2008
 

I have very little experience with perl. I have a plx/tmpl page that displays a data table based on a @records array. I am able to sort the array by a subkey.

I want to create links out of the column headers then change the sort order based on what the user clicks (ascending/descending). The links change the 'sort' querystring value. I am able to get the querystring with:


my $sortvar = param('sort');


I coded the tmpl file to change the link when the user clicks it, that part works fine.
I tried this in my plx page but it does not do anything:


if ($sortvar == '1')
{
my @records = map { $_->[0] }
sort { $b->[1] cmp $a->[1] }
map {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
my ($d,$m,$y) = split(/\s+/,$date);
$d = $d<10 ? "0$d" : $d;
$m = $month{lc substr $m,0,3};
[$_,"$y$m$d"]} @records;
}
elsif ($sortvar == '2')
{
my @records = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map {(my $date = $_->{COMPDATE}) =~ s/<font color="#FF0000">//;
my ($d,$m,$y) = split(/\s+/,$date);
$d = $d<10 ? "0$d" : $d;
$m = $month{lc substr $m,0,3};
[$_,"$y$m$d"]} @records;
}

Any ideas?

  Re: Sorting by column on webpage  yesti at 23:28 on Tuesday, February 05, 2008
 

The problem: @records was scoped wrong. It was declared globally way above this code snippet so taking out the 'my' in front fixed the problem. As is, it was local to the if statement.









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Error configuring webservice identity in reporting services 2005
•  Re: Sorting by column on webpage
•  Re: file upload
•  how to create a forum in asp.net
•  how to create a forum in asp.net
•  how to create a forum in asp.net
•  Re: facing problem in enabling a check box
•  div with position absolute?
•  Need help with file I/O


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008