SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
May 15, 2003, 09:35 #1
- Join Date
- Mar 2003
- Location
- ontario
- Posts
- 74
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
joining of field from one table to another
JOINING? Would it be a join that I would use to get the 'cust_id' (auto-incremented from Mysql) from table CUSTOMER into the other tables of CARD PAYMENT & CUST ORDER. If so, how? Also, does this work even if they are queried at the same time?
// database connection
mysql_connect("$host","$user","$pass" );
// database selection
mysql_select_db($database);
// Insert customer information
mysql_query("INSERT INTO customer VALUES(
'$cust_id',
'$posted',
'$firstname',
'$lastname',
'$company',
etc...
// Insert payment
mysql_query("INSERT INTO card_payment VALUES(
'$posted',
'$cust_id',
'$cart_id',
'$total')" );
// Insert customer order
mysql_query("INSERT INTO cust_order VALUES(
'$posted',
'$cust_id',
'$cart_id')" );
-
May 16, 2003, 01:26 #2
- Join Date
- Mar 2002
- Location
- Osnabrück
- Posts
- 1,003
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi.
Do you want the id which MySQL creates when a new record is added?
You can get it with PHP using mysql_insert_id()
http://www.php.net/manual/en/functio...-insert-id.php
This can then be put in another table
PHP Code:mysql_query('INSERT INTO ... ') or die(mysql_error());
// get the auto_incremented id
$id = mysql_insert_id();
// insert it into another table
mysql_query("INSERT INTO sometable VALUES ($id)") or die(mysql_error());
Christian
Bookmarks