FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


foreign key!





kawkazEE
i am tryin to store a customers info in the 'customers_tbl' and that same customers order into the 'orders_tbl'. my primary key in the orders_tbl is called 'orders_id' and i have a 'customers_id' column in the orders_tbl where in i can store the customers id of a particular customer with the particular order. the problem is that if i save the customers order in the orders_tbl how do i get the customers id so that i can store it in the orders_tbl in thje customers_id field. ive read a tutorial that says i should use a foreign key but it wasnt that clear. anybody who knows that answer please help. Sad Sad
asiddle423
In MySQL you would have to use the WHERE syntax to link the tables together

Ill take some reference from my SQL book on joining tables, oh and I would highly adivise an SQL book, I have the SAMS Teach Yourself SQL in 10 Minutes, this book is good for reference.

a join example

SELECT vend_name, prod_name, prod_price
FROM Vendors, Products
WHERE Vendors.vend_id = Products.vend_id

hope this helps
any more information on this i would be happy to help but im like you still learning new things with MySQL
kawkazEE
tnx but that type of join is for retrieving records, but what if am tryin to insert records... hope somebody had a better way... Laughing Crying or Very sad
Rhysige
I think your looking for mysql_insert_id() if you use that function straight after the insert on your first table it will retrieve the ID of the last insert. You can then store this in a variable and use it in your next insert.
kawkazEE
oh really.... tnx!!! ill go try it. some of the stuff i found was to search the id according to the details of that id... and im not comfy w/ it.. Crying or Very sad
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.