Further contribution: Page numbering system for $group and $search

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

As promised in my earlier contribution, I have managed to script a pagenumbering sequence that will produce some statistics about the number of item found for each search, the number of pages they will produce (depending on $numtolist) and the links to all those pages. The script below is the entire script for the type eq 'search' , however this can also be applied to type eq 'group' . And some of the lines are able to be swapped around so that page numbers are printed above the line/page stats. ############### # Barry's script starts here; elsif ($type eq 'search') { my($matches) = 0; my($i) = $pos; while (($matches < $numtolist) && ($i < $SIZE)) { $_=$LINES[$i]; if (index(lc $LINES[$i],lc $FORM{'search'}) >= 0) { $matches++; ($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_); &print_item; } $i++; } print "\n"; # and ends here albeit for the last } at the very bottom of this page. ################# # William's pagenumbering script starts here: $num = grep(/$FORM{'search'}/i, @LINES) ;#produces the number of lines @num = grep(/$FORM{'search'}/i, @LINES); $count = int(($num / $numtolist)+ '0.99'); #produces the number of pages foreach $_(@num) { ($itemid, $name, $price, $descrip, $image, $weight, $itemurl, $group) = split(/\|/,$_); push @pagestart, $itemid; } if ($num > $numtolist) { $page = "pages"; $these = "These"; $counted = "$count"; $numbers = "numbers"; $starts = "start"; } else { $page = "page"; $these = "This"; $counted = "only"; $numbers = "number"; $starts = "starts"; } if ($i < $SIZE) { print "$num items found on $count $page.
\n"; } else { print "
\n"; } print "
Pages to view are below:
\n"; # This next section produces the page numbers 1..$count and places hypertext links on each number at the $pos where each page should be searched for from (if that sentence isn't confusing...!?) $itembegin = (@pagestart[0]-1); print "1\n"; foreach $itemid(@pagestart[0,29,59,89,119,149,179,209,239,279,309,339,369,399,429,459,489,519,549,579,609,639]) { # This can be however many numbers you like! # My $numtolist is set at 30, but you can change this, as long as #your number sequence starts at 0 and increases every $numtolist. push @pages, $itemid; } $ret = shift@pages; foreach $count(2..$count) { $factor = ($count-2); print " $count\n"; } # and ends here, with the last } of Barry's script following. } Try is out on your 'group' search also, but remember to change only 'search' in my script to 'group'....do not change any of Barry's scripting otherwise your search facility will not work. The scripting to produce the linked page numbers for type eq 'all' is available at this question/answer site in my previous contribution. Any probs...email me please. As always...feedback is appreciated! Hope this works for you.

-- William Kolln (wkolln@cia.com.au), May 01, 1998


Hi William,

I've been trying to add your script into smart but have been experiencing difficulties. Could it be that it has beem somewhat scrambled by going onto the web?

I have tried sorting out the line breaks etc, but to no avail. I would really like to try the script out. Would it be possible to mail it to me directly?

Thanks for you help.


-- Rufus (rufus.biggs@m-audio.co.uk), June 06, 2000.

Moderation questions? read the FAQ