PHP Templates: Homepage

Hi,

I am beginning the process of creating a MySQL, PHP, CSS web site.

I understand since the product pages are similar it makes sense to have a template and use the ‘Get’ function in the URL to populate a template php file.

However, as always, there is only one Homepage. Do you recommend designing this ‘straight on the page using HTML and CSS’ or would you recommend using the database and PHP as well as HTML and CSS??

What is the most popular method?

Matt.

You’re going to need to have it all in mind.

The very first thing you ask yourself is “Do I need a database for this website?” (PHP in this context is essentially a bridge between HTML and MYSQL). I’m assuming your answer is ‘Yes’.

The Database probably comes ‘second’, in my design theory.
First: What do I need to store information about? (This list will become your tables)
Second: What do I need to store about each of these? (This will be the fields in your tables)
Third: How do these things relate? (This will create your foreign keys and join tables)

Now you’ve got a database. You know what you’re going to be storing. Now design your template to display those things.

I have done a Google search on “Foreign Keys” and “Join Tables” but I do not understand still. I think it relates to when there is more than 1 database for content but I’m not sure.

What would be an example of ‘wording’ or ‘coding’ for an entry into a field for “foreign keys” and “join tables”?

Matt.

A Foreign Key associates two tables on a 1-to-1 basis.
A Join Table is used to associate two tables on a 1-to-many (or many-to-many) basis.

Okay. Lets take… a store.

A store has products. It has orders for those products. It has customers.

Your products table has a structure soemthing like…
productid (BIGINT(9))
productname (varchar(255))

Your customer table has a structure something like…
customerid (BIGINT(9))
name (varchar(255))

Your orders table has a structure something like…
orderid (BIGINT(9))
customerid (BIGINT(9)) <– Note: THIS IS A FOREIGN KEY.
date (DATE)

Now - each order has 1 customer. So we use the foreign key to be able to say ‘Christopher Smith made Order #2105’, without having to store Christopher’s information over and over.

Each order, however, can have many products associated to it. Chris might have bought 5 shirts, 3 pairs of pants, and a partridge in a pear tree in order #2105.

Obviously, we cant add fields to the order table for ‘item1’,‘item2’, etc, because Chris could order 200 different things in one order, or he could order 1 thing. So, we need a join table.

order_to_product (what i’m gonna call my join table)
orderid (BIGINT(9))
productid (BIGINT(9))
quantity (int(5))

Now, Chris can order as many things as he likes, and I can store each item as a row in the join table, without flooding my order table with useless fields.