Getting entry to top of list

They have: 21 posts

Joined: Nov 2004

Hi, I'm working on a forum script which does what it's supposed to do, except for one thing. That is, listing the latest reply or new thread at the top of the topic list correctly.

I had help on the code below from a forum which is now closed. The code works, but - this happens:

If this month is say May, then the latest post goes to the top of the list (only because May is at the top).
If someone posts a reply to a thread made in say April or March, then the reply only goes to the top of the section in the list where that particular month is displayed. Which is not what I want it to do.

Does that make sense?

What is needed to make any posting go to the top of the whole list, regardless of the month the original thread began?

I do not know how to do that (I'm not all that good a programmer).

sub dispMonths {
my($filename) = @_;
$filename =~ s/[\^<>'\$!#;\*\?\&\|\`\/\~\\\(\)\{\}\"\n\r]//go;
$filename =~ s/\.\.//go;
# open file
$thefilenm = "$cgidir/$forumdata/$filename.txt";
if (open(DATA,"$thefilenm")) {
my %records;
while (<DATA>) {
chomp;
my @data = split(/_/);
my $date = join '', (split(/[\/:-]/, $data[5]))[2,1,0,3,4,5];
push @{$records{$date}},$_;
}
close(DATA);

foreach my $key (sort {$b cmp $a} keys %records) {
@sorted = "@{$records{$key}}";
# split new array
foreach  $line (@sorted ) {
if ($line ne '') {
@info = split (/_/, $line);
$num = $info[0];
$subject = $info[1];
$name = $info[2];
$date = $info[3];
$responses = $info[4];
$replytime = $info[5];
$replyname = $info[6];

# print it all out
print qq ~
<TR valign="top"><td>
<A HREF="$ENV{'SCRIPT_NAME'}?msg=$num" onFocus="if(this.blur)this.blur()"><b>$subject</b></A>
<div class="small">Posted on: $date</div></td>
<td>$name</td>
<td>$responses</td>
<td align="right">$replytime<br>by $replyname&nbsp;<A HREF="$ENV{'SCRIPT_NAME'}?msg=$num#$responses" onFocus="if(this.blur)this.blur()">$viewpost</a></td></TR>
~;
}}}}}

I hope someone can help please,
Thanks

They have: 10 posts

Joined: May 2009

foreach my $key (sort {$b cmp $a} keys %records)
why you are sorting it if you need the latest post on the top regardless of the month or date? If you sort then the array of data are re-arranged. Please try simply by not sorting them. It may work.

They have: 21 posts

Joined: Nov 2004

I don't know. Someone else helped me out on that (re: 'forum which is now closed') - I've never used hashes before. I've tried getting rid of the sort, but that just wipes everything out.

They have: 21 posts

Joined: Nov 2004

This been solved elsewhere. Topic finished.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.