You do not need a primary key in table 3 to make it work, but are confusing the issue by having the orderitemid in table 3. You need to use a join from t1 to t2 using the customerid fields, you would be better using the name id in each table as the primary key,:
CUSTOMERS
id int(11) primary key auto_increment,
firstname varchar(...................
lastname varchar(.......... etc
ORDERS
id int (11) primary key auto_increment,
orderdate date .......
customerid int(11),
ITEMS
orderid int(11),
productid int(11),
quantity int(.............
Use a select on t1 and t2 :
$orderres = mysql_query("select firstname,lastname,address,city,orders.id as orderid,tax,shipping from orders left join customers on customerid = customers.id where orders.id = '$orderid'");
This gives the basic headings for an invoice etc.
Then:
$partsres = mysql_query("select productid,quantity from items where orderid = '$orderid'");
$partslist = "PRODUCT QUANTITY ...
//The above should ideally set up a table with the headings in the //first row. Then:
while ($partsrec - mysql_fetch_array($partres){
$partslist .= "$partsrec[productid] $partsrec[quantity]...
//Again set up a table row, you also need to look up the part description from another table by id, this could be another join.
}
This becomes very flexible, it allows for multiple parts, changing any one piece of data (say the product description) causes it to follow through.
If this grows, it may pay to make the customer a clients table, using either company names or the combined firstname,lastname and the address, then make a contacts table for use if you have several contacts at one company. This prevents you being bogged down by changes later. Foreign keys also cause problems with later modifications.