Hi all,
I have a question for you. I am writing user submitted information to a tab delimited text file and reading it back into a web page via ajax. I am reading the text file from the bottom up (newest posts first) and displaying 5 results per page. My problem is in displaying my Previous and Next buttons. If I have less than 5 posts, my page displays a bunch (10) empty display tables. Can someone please guide me in the right direction here? Sorry, the code is pretty long, the issue (I believe) starts around line 60, right after $a = $limit
Any help is much appreciated!
Thanks
I have a question for you. I am writing user submitted information to a tab delimited text file and reading it back into a web page via ajax. I am reading the text file from the bottom up (newest posts first) and displaying 5 results per page. My problem is in displaying my Previous and Next buttons. If I have less than 5 posts, my page displays a bunch (10) empty display tables. Can someone please guide me in the right direction here? Sorry, the code is pretty long, the issue (I believe) starts around line 60, right after $a = $limit
Code:
#!/usr/bin/perl -wT
#print "Content-type: text/html\n\n";
print header(-expires=>'-1d');
use CGI qw/:standard/;
print "<div style='text-align:right;'><a href='#kudosform' class='black'>Submit a kudos for a colleague</a></div>";
my @tname;
my @temail;
my @say;
my @other;
my @kudos;
my @fname;
my @femail;
my @ts;
open (FILE, 'posts.txt');
while (<FILE>)
{
chomp;
($toName, $toEmail, $wantedToSay, $other, $kudos, $fromName, $fromEmail, $timestamp ) = split("\t");
push(@tname, $toName);
push(@temail, $toEmail);
push(@say, $wantedToSay);
push(@other, $other);
push(@kudos, $kudos);
push(@fname, $fromName);
push(@femail, $fromEmail);
push(@ts, $timestamp);
}
close (FILE);
my $results = $#tname;
my $limit = undef;
my $nxt = undef;
my $pre = undef;
if(!$ENV{"QUERY_STRING"})
{
#print "NO QUERYSTRING ";
# set limit to the number of results if there's no value from query string.
$limit = $results;
#print $limit."<br><br>";
}
else
{
#print "QUERY STRING ";
# try to get limit value from query string. Only there if were not on page 1
$limit = $ENV{"QUERY_STRING"};
#remove the limit= from query string to just obtain value
$limit = substr($limit, 6);
#print $limit."<br><br>";
}
$a = $limit;
if($results > 0)
{
print "No kudos found.";
}
else
{
print "<strong>".$results." kudos found</strong> Browse: ";
#now print the paging results
if($limit >= $results)
{
$nxt = $limit - 5;
print "<a href='javascript:void();' title='".$nxt."' class='black' onclick='getNext(".$nxt.");'>next</a>";
}
elsif($limit >= 0)
{
$nxt = $limit - 5;
$pre = $limit + 5;
print "<a href='javascript:void();' title='".$pre."' class='black' onclick='getNext(".$pre.");'>previous</a>";
if($nxt < -1)
{
# do nothing
}
else
{
print " | <a href='javascript:void();' title='".$nxt."' class='black' onclick='getNext(".$nxt.");'>next</a>";
}
}
else
{
$pre = $limit + 5;
print "<a href='javascript:void();' title='".$pre."' class='black' onclick='getNext(".$pre.");'>previous</a>";
}
print "<br /><br />";
while($a > ($limit - 5))
{
if($a == 0)
{
exit;
}
print "<style>";
print "#display { width:100%; text-align:left; } ";
print ".kudosContainer { width:100%; height:auto; margin:0; padding:0; border: 2px solid #94214b; } ";
print ".toname { width:10%; height:auto; margin:0; padding:0; float:left; display:inline; border:1px solid white; } ";
print ".name { width:30%; height:auto; margin:0; padding:0; float:left; display:inline; border:1px solid white; } ";
print ".fromname { width:10%; height:auto; margin:0; padding:0; float:left; display:inline; border:1px solid white; } ";
print ".fname { width:30%; height:auto; margin:0; padding:0; float:left; display:inline; border:1px solid white; } ";
print ".logo { width:10%; height:auto; margin:0; padding:0; float:left; display:inline; border:1px solid white; } ";
print ".kudos { clear:both; width:100%; height:auto; background-color:#ede3ce; margin:0; padding:0; }";
print "</style>";
print "<style media='print'>";
print ".kudosContainer { width:100%; height:800px; margin:0 0 60px 0; padding:0; border: 2px solid #94214b; }";
print ".kudos { clear:both; width:100%; height:750px; background-color:#ede3ce; margin:0; padding:0; }";
print "#display { display:none; } ";
print "a { display: none; } ";
print "</style>";
print "<div class='kudosContainer'>";
print "<div class='toname'><h3>TO:</h3></div>";
print "<div class='name'><span style='text-decoration:underline';>".@tname[$a]."</span></div>";
print "<div class='fromname'><h3>FROM:</h3></div>";
print "<div class='fname'><span style='text-decoration:underline';>".@fname[$a]."</span></div>";
print "<div class='logo'><img src='/etd/graphics/kudosSm.gif' width='103' height='41' /></div>";
print "<div class='kudos'><div style='margin:0 5px;'><h3>I wanted to say: </h3><strong>";
if(@say[$a] eq "Thanks")
{
print "Thanks, because...";
}
elsif (@say[$a] eq "congrats")
{
print "Congratulations because...";
}
elsif (@say[$a] eq "fabjob")
{
print "Fabulous job because...";
}
elsif (@say[$a] eq "hero")
{
print "You're my hero, because...";
}
elsif (@say[$i] eq "rockstar")
{
print "You're a rock star, because...";
}
elsif (@say[$a] eq "madeday")
{
print "You made my day, because...";
}
elsif (@say[$a] eq "trooper")
{
print "You're a real trooper, because...";
}
elsif (@say[$a] eq "fab")
{
print "You're fab, because...";
}
elsif (@say[$a] eq "right")
{
print "You've got the right stuff, because...";
}
elsif (@say[$a] eq "other")
{
print @other[$a].", because...";
}
else
{
print "Thanks, because...";
}
print "</strong><br />".@kudos[$a]."<br /><div align='right'><a href='/cgi-etd/kudos/printkudos.cgi?id=".$a."' id='print' target='_blank' class='black'>Print Friendly</a></div></div></div>";
print "</div><br />";
$a--;
}
}
Any help is much appreciated!
Thanks