Foreign Key with two tables

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sharky
Forum Newbie
Posts: 17
Joined: Sun Jun 04, 2006 12:31 pm

Foreign Key with two tables

Post 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 ........?");
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post 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
sharky
Forum Newbie
Posts: 17
Joined: Sun Jun 04, 2006 12:31 pm

Post by sharky »

Thanks. But how can I connect two tables at the same time?
tables :: orders, order_details
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

Code: Select all

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