Page 1 of 1

Foreign Key with two tables

Posted: Thu Jul 13, 2006 1:08 am
by sharky
I have two tables :: orders and order_details, in db mobile_phones. Let say somebody makes an order, all the information goes to:

order --> ID, user_ID, email, address, postal_code, province, country, date_stamp
order_detail--> ID, FK_order, brand, price, quantity, date_stamp

I wanna display them in a page. ID and FK_order are the FK. I'd like to ave 4-5 orders in 2 page, then there's button next or previous. How do I do that?

$query= sprintf("SELECT * FROM ........?");

Posted: Thu Jul 13, 2006 2:38 am
by GM
Are you using MySQL? If so there is a LIMIT keyword you can attach to the query:

Code: Select all

SELECT * FROM table LIMIT 5;
returns only the first 5 results

Code: Select all

SELECT * FROM table LIMIT 5,10;
shows only results 6 to 15 (start at 5, return 10 records).

You can pass a parameter in the URL to use as the offset. (http://www.mysite.com/orders.php?start=10) for example.

Hope this helps

Posted: Thu Jul 13, 2006 1:02 pm
by sharky
Thanks. But how can I connect two tables at the same time?
tables :: orders, order_details

Posted: Fri Jul 14, 2006 3:04 am
by GM

Code: Select all

SELECT * 
FROM order o, order_detail d 
WHERE o.id = d.fk_order