Friday, October 31, 2008

Class 6 Assignment

You can view my e-commerce store website here.

The page nav links all work (except for Show All). When you click on page 1, 2 or 3 it requests store.php?page=# where # is the page number you selected. I use $_GET['page'] to figure out what page is being requested.

I only have one store.php file. By default it displays the first 9 products. When you select another page, it figures out what 9 products to display based on the page number. Since the variables for each product contain a number corresponding to that product, I have the PHP code build the variable name to call based on which product it is trying to display.

I have a single statement to print the product thumbnail to the page which is nested in a loop. The loop gets it's starting and ending values based on a calculation performed on the page number which is being viewed. So if you are viewing page 2, it calculates $startProd to be 10 and $endProd to be 18, then loops from 10 to 18, each time printing to the screen the function productInfo() which is passed 4 variables: the ID, image path, name, and description. Every third iteration of the loop prints a
since we are working on a 3x3 grid. This is done by a simple if...elseif statement. Each iteration of the loop incriments a variable $brCount. Everytime it hits 3
is printed and the variable is reset to 1.

I didn't like the idea of hard coding all the product info into variables, but since we have not yet learned about MySQL, I had no choice. However, I opted to create a separate file containing all the variables for the product info and called it db.php.

The "displaying 1 to 9 of 27" is also calculated based on which page is being viewed. The 27 is static, but 1 and 9 are just a couple variables I was already using, $startProd and $endProd.

The Prev and Next are also calculated based on the current page number. Prev is $page+1. When you are on page 1, Prev is calculated to be 0. Rather than futz with some code (I'm tired) I just tested the value of $page at the top of the store.php file and set it to 1 if it starts as 0.

1 comment: