Contribution: Page links for generated pages

greenspun.com : LUSENET : S-Mart Shopping Cart : One Thread

###################################### # Please unwrap this in your text editor to read it properly if it # doesn't unwrap in your email. ##################################### # Coding for creating page number links # at the bottom of your generated pages for S-Mart. # Produced by William Kolln, Sydney Australia. # This is part of my contribution to enhance Barry's program for all those users # who have assisted me during the establishment of my store. # The UNsound Records Webstore will go on-line mid-May. # PLEASED NOTE..... # This particular coding only works for the situation where # you search on ALL items on your database. # It does not work for searches performed on groups etc. I have not developed this # yet....but am in the process of doing so. # This code works well in my program, however, I give no guarantee it will work in yours. # This is the entire code for this conditional statement in the sub gen_page { subroutine. # This code removes the existing line # print "
Next $numtolist items
\n"; # using the Next $numtolist method ###################################### ################################ # This is the existing coding from Barry's S-Mart.cgi ################################# if ($type eq 'all') { my($max) = $pos + $numtolist; if ($max > $SIZE) { $max = $SIZE; } for ($i=$pos;$i<$max;$i++) { $_=$LINES[$i]; ($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_); &print_item; } print "\n"; ################################## # To here....... # plus the last curly bracket at the end of this routine. ######################################################## # Hereafter is the new code that will produce something like this: # Pages to view are: # 1 2 3 4 5 6 7 8 9 (with hyperlinks on each number) # 129 items found on 9 pages # (depending on what you have your $numtolist set as in the smart.cfg ######################################################## $num = grep(/$lines/, @LINES) ;#produces the number of lines in the database $count = int(($num / $numtolist)+ '0.99'); #produces the number of pages to display those lines $base = 30; # specifies a scalar variable if you $numtolist is equal to 30 print "All pages to view are: \n"; print "
\n"; print "1\n"; # this sets the link for the first $pos=0 to create the first page foreach $factor(2..$count) { # $factor scalar is initialized and repeated for each number produced in the $count variable above starting at 2, page 1 has been set above. $factors = (($base*$factor)-$base); # $factors scalar equals this equation and is set at $pos in the line below with the covering each number produced above. print " $factor\n"; } print "
\n"; if ($num > $numtolist) { # conditional statement that is the number of lines is greater than the $numtolist variable for each page $page = "pages"; # $page variable initialized and given a string value. } else { # otherwise if the number of lines is not greater than the $numtolist $page = "page"; # produces this string variable. } if ($max = $SIZE) { # if the maximum returns equals the size of the database print the line below. print "$num items found on $count $page.
\n"; } ############################# # Last curly bracket follows for this conditional sequence. ############################ } ############################## # End of this conditional sequence. ##############################

-- William Kolln (wkolln@cia.com.au), April 22, 1998

Moderation questions? read the FAQ