You Can Traverse My Guestbook Pages By Clicking On Arrows

Most of the posts in my guestbook are shameless advertisements that posters submit too increase the number of links to their website. Now and then I get an actual comment about my website, usually about my blogs. Recent posts about my blogs have been very flattering; I feel guilty! Most of my blogs aren't as good as they used to be, because I've been so short on time of late.  Well, I got a four day weekend for Christmas, so this is a good time to blog. Blog about what? Blog about my guestbook!

The code for the guestbook is a Perl script, and I create comments at the top of the script whenever I make a change to the code. Here's the notes I've entered so far:

         
     # February 5, 2013. I had originally copied and pasted my escape character code to wherever it was needed in this script.
     #                   I just created a single subroutine for converting escape characters to display characters
     # February 5, 2013. All my visitors seem to be making entries programatically, and putting their e-mail addresses
	  #                   in the phone field. I wrote a subroutine to check if the phone field is an e-mail address and
     #                   if #email isn't an e-mail address; copy $phone over $email in this case.
     #
     # January 30, 2013. Read this interesting article at http://webdesign.about.com/od/layout/a/aa042307.htm
     # The author, Jennifer Kyrnin, described how to use <ul> to split up a web page into tabs
     # Here's what I need to do
     #
     # 1. Open up the Excel spreadsheet (read only)
     # 2. Count the number of rows I have and then divide by 100 to get the number of html pages
     #    I need to create; add 1 if there is a remainder.
     # 3. Create page #1, with tabs at the top for each page; send this page to the user
     # 4. The tabs call the same page with different parameters; 0, 1, 2, etc.
     #
     # December 18, 2013, Returned to MS Access, this time MS Access 2000. Instead of using MS Access 2010
     # Of course this required a code change in this script, too.
     #
     # February 10, 2014; Now displaying the tab number currently being viewed - have this commented by date
     #
     # December 26, 2014; put arrows on the page so the user can backup or forward by clicking them, instead of clicking on the tabs at the top of the page     

OK, I admit it, there are no notes before February 5, 2013. If I had notes going back to 2012, they would say when I changed the database for this guestbook from MS Access 2010 to MS Excel 2000; hopefully with comments about the slower page loads after the switch. The notes for January 30, 2013 don't mention  it, but that modification was done to improve the load time of the guestbook; broke the guestbook up into tabs. You can click on a tab too see what's on it's page, but I thought it would be nice to have a couple of arrows you could click on to change tabs incrementally.  

Looking at my program comments again, on February 10, 2014 I added a line of text that tells the user what tab he/she is on. This blog is about the next comment, dated December 26, 2014; the code in my Perl script is right after the code for the 02/10/2014 comment, too:

   print "You are currently looking at tab:" .$myTab."<br>"."*******************************"."<br>";

   my $leftTab = int($myTab/100) - 1; # DMK 12/26/2014
   my $rightTab = int($myTab/100) - 1;
   if ((($myTab == $rows) && (($myTab % 100) != 0)) || ($myTab < $rows))
   {
      $rightTab++;
   }

   if ((($myTab > 100) && ($myTab < $rows)) || (($myTab == $rows) && (($myTab % 100) == 0)))
   {
      $leftTab--; 
   }

 

$myTab contains the value displayed on the tab; e.g., the first tab (0th tab) says 100 and the next tab says 200, etc. Say we have 9900 rows; the last tab will say 9900 and we have 99 tabs. We can write this as n * 100, where n = number of tabs. However, if we have 9901 rows then we need 100 tabs, the number of rows in my guestbook is not a multiple of 100 and the last tab will have a number of the form (n - 1) * 100 + remainder; remainder is the the remainder left over from long hand division of (number of rows)/100 (think back to the 3rd grade). There is an operator for getting the remainder, called modulus; %. So we can write the tab number of the last tab as (n - 1) * 100 + ((number of rows) % 100). 

Perl has an int() function that truncates the decimal part of a number, so int(9900/100) = 99 and int(9901/100) = 99. Look at my code above; I use the int() function when calculating the tab argument to send to my web server (the tab argument being the tab to display). The tab argument starts with zero and ends with n - 1 (n is still the number of tabs). At the start of my code I have $leftTab and $rightTab both set to the current tab argument (except when we are on the last tab and the number of rows is not a multiple of 100; it's 1 less in this case). E.g., the first tab has a $myTab value of 100, so $leftTab = int(100/100) - 1 = 0. Notice that for the change in $leftTab I check to make sure that we are not on the first tab ($myTab > 100); i.e., it is a special case.  If we are on the last tab (the other special case) then there are two possibilities; (1) say $myTab is 9900, then the argument for the web server (CGI argument) is 98 and we want to decrement (CGI argument 98 corresponds to the tab numbered 9900, and CGI argument 97 corresponds to the tab numbered 9800), but (2) if  $myTab is 9901 then the CGI argument is 98 and we don't want to change the value because it will take us to the tab with a 9900 on it. The same logic goes for $rightTab; if you're on the last tab you can only increment if (($myTab % 100) != 0), because we already set $rightTab to one less then the current CGI argument in this case.

BTW, testing this way is not cut in stone. I could've arranged my tests in a completely different manner, but I wanted to setup my tests so I'd be testing to see if I should increment $rightTab or if I should decrement $leftTab. Just remember that what is important in this type of test is your boundary conditions (the first and last tabs in my guestbook).

Return To My Blog Page       Return To My Programming Page