Inserting into two tables...

2002-09-23 Thread Chuck \PUP\ Payne

Ok, Let's try this again, for some reason this didn't post from early today.

I have db that has two tables that I am needing to post the same information
into both tables, I can't use ID. So I am want to see if there is a sql
statement that will let me or how I can do with a php page.

I am sorry to ask, I have looked around to see if there any on the net or in
my mysql and php books but this seems like a weird task.

Chuck Payne
Magi Design and Support


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: Inserting into two tables...

2002-09-23 Thread Derek Scruggs

 I have db that has two tables that I am needing to post the same
 information
 into both tables, I can't use ID. So I am want to see if there is a sql
 statement that will let me or how I can do with a php page.

I'm not a SQL guru, but I'm pretty sure SQL doesn't allow this. (Objects in
PostgreSQL and other object databases essentially allow this, but I suspect
the underlying SQL is iterative.)

But it's pretty simple to do. Just create your insert statement inside a
function with a variable for the table name, then call the function with the
table names.

?
function foo($table) {
   $sql=INSERT INTO $table VALUES(...);
   //connect to db
   $result=mysql_query($sql);
   //error handling here
}

foo(table1);
foo(table2);
?

If you need them to have the same ID and you're using autoincrement, you can
add an optional parameter $ID and have the function return last_insert_id if
$ID is not set. Capture the ID the first time you call the function, then
pass that ID as a parameter the second time.

$ID=foo(table1);
foo(table2,$ID);

See http://www.php.net/manual/en/functions.arguments.php for more info on
function arguments in PHP.

-Derek


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php