Current location: Hot Scripts Forums » Programming Languages » Perl » problem with next and previous links

problem with next and previous links

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-05-04, 02:13 PM
abtimoteo abtimoteo is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Question problem with next and previous links

i have a flat-file news database. i would like to limit the printing of its contents to two lines per page. i have written the necessary script based on a tutorial by ray street. with this script, i can print the first page - that is, first two lines of the flat file. but the next and previous links do not work. the print statements change the address at the location bar of the browser. but the content of the web page is not replaced. (it is likely that i have not fully understood mr street's tutorial.)

please help me find the error in the code. important: a perl module on paginating perl files is out of the question because of limitations imposed by my web host.

you will find the complete script below. thanks ...

-----

#!/usr/bin/perl

# REQUIRED SCRIPTS

# Call in the necessary files.

require "ABTi.pm";
require "NewsManagerConstants.pl";
require "startHTML.pl";
require "printbody.pl";
require "printhr.pl";
require "starttable.pl";
require "starttr.pl";
require "endtr.pl";
require "endtable.pl";
require "printNewsManagerStaticNavigationElements.pl";
require "printPerlCGIProgrammingbyABTi.pl";
require "endHTML.pl";

&startHTML ("$MyOrganization | Tech News");

&printbody;

# Extract data from the flat-file database. Open "xyzNewsSubmissions.dat" for reading.

open (NEWSSUBMISSIONS, "xyzNewsSubmissions.dat")
|| die "Could not open file: $!\n";

# Lock the file for exclusive access.

# flock (NEWSSUBMISSIONS, $ExclusiveLock)
# || die "Could not lock file: $!\n";

# Read the file into the array named @NewsSubmissions.

@NewsSubmissions = <NEWSSUBMISSIONS>;

# Unlock the file.

# flock (NEWSSUBMISSIONS, $Unlock)
# || die "Could not unlock file: $!\n";

# Close the file.

close (NEWSSUBMISSIONS)
|| die "Could not close file: $!\n";

# Count the number of submissions.
# Do this by calculating the size of the array.

$xNewsSubmissions = @NewsSubmissions;

# Set the number of submissions
# that should be printed per page.

$xNewsPerPage = 2;

# Count the number of results by page.

if ($xNewsSubmissions != 0)
{
$xNewsPages = int ($xNewsSubmissions / $xNewsPerPage); # Example: 3 / 2 = 1.5
if (($xNewsPages * $xNewsPerPage) != $xNewsSubmissions) # Example: (1.5 x 2) _
{
$xNewsPages++; #
}
}

if (!defined($counter))
{
$counter = 1;
}

$FirstResult = (($counter -1) * $xNewsPerPage) + 1;
$LastResult = $FirstResult + $xNewsPerPage -1;

if ($LastResult > $xNewsSubmissions)
{
$LastResult = $xNewsSubmissions;
}

print "<center>\n";
print "<table cellpadding=$cellpaddingtd cellspacing=$cellspacingtd width=98%>\n";
&starttr;
print "<td><h1>Tech News</h1></p></td>\n";
&endtr;
&endtable;
print "</center>\n";

&printhr;

print "<p align=center>Viewing $FirstResult to $LastResult of $xNewsSubmissions results.</p>\n";

foreach $NewsSubmission (@NewsSubmissions)
{
if ($counter >= $FirstResult && $counter <= $LastResult)
{
chomp ($NewsSubmission);
($Author, $EmailAddress, $Headline, $News) = split (/\|/, $NewsSubmission);
$NewsSubmission =~ s/\|//g;

print "<p></p>\n";

print "<center>\n";
print "<table cellpadding=$cellpaddingtd cellspacing=$cellspacingtd width=98%>\n";

&starttr;
print "<td><h1>$Headline</h1></td>\n";
&endtr;

&starttr;
print "<td><p><font size=\"-1\" color=#a1a1a1>Posted by:</font> <a href=mailto:$EmailAddress>$Author</a></td>\n";
&endtr;

&starttr;
print "<td><p>$News</td>\n";
&endtr;

&endtable;
print "</center>\n";

print "<p></p>\n";
}
else
{
# Do nothing.
}
$counter++;
}

$PreviousPage = $counter - 1;
$NextPage = $counter + 1;

# The "previous page" link:

if ($counter == 1)
{
$PreviousLink = '';
}
else
{
$PreviousLink = "<a href=\"$MyWebsite/cgi-bin/printJumpPage.pl?counter=$PreviousPage&xNewsPerPag e=$xNewsPerPage\">" . "<<" . "</a>";
}

# The "next page" link:

if ($counter == $xNewsPages)
{
$NextLink = "";
}
else
{
$NextLink = "<a href=\"$MyWebsite/cgi-bin/printJumpPage.pl?counter=$NextPage&xNewsPerPage=$x NewsPerPage\">" . " >>". "</a>";
}

# Create the links.

if ($xNewsPages > 1)
{
$DynamicLinks = $PreviousLink;
$PageNumber = 0;
while ($PageNumber < $xNewsPages)
{
$PageNumber++;
if ($PageNumber == $counter)
{
$PageIndicatorLink = $PageNumber;
}
else
{
$PageIndicatorLink = "<a href=\"$MyWebsite/cgi-bin/printJumpPage.pl?counter=$PageNumber&xNewsPerPage= $xNewsPerPage\">" .$PageNumber. "</a>";
}

$DynamicLinks = $DynamicLinks . $PageIndicatorLink;
}
$DynamicLinks = $DynamicLinks . " " . $NextLink;
}
else
{
$DynamicLinks = "";
}

print "<p align=center>$DynamicLinks</p>\n";

&printhr;

&printNewsManagerStaticNavigationElements;

&printPerlCGIProgrammingbyABTi;

&endHTML;

# End printJumpPage.pl.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Insert Previous Next Record Links cebuy PHP 2 01-02-04 09:52 AM
Previous Next links.. PLEASE HELP!! SCHOOL DUE DATE! Soulidified PHP 1 12-29-03 10:29 PM


All times are GMT -5. The time now is 04:31 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.