[PHP-DB] select particular columns in query

2004-12-08 Thread blackwater dev
Hello,

I want to create a new row in the db by copying an existing one.  My
db has an auto incrementing id so I can't simply do insert into cars
select * from cars where id=$id as this throws the primary key error. 
How can I do this with out specifying each column?

Thanks!

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] select particular columns in query

2004-12-08 Thread Bastien Koert
INSERT INTO `dbname`.`newtablename`
SELECT *
FROM `dname`.`oldtablename` ;
bastien
From: blackwater dev [EMAIL PROTECTED]
Reply-To: blackwater dev [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [PHP-DB] select particular columns in query
Date: Wed, 8 Dec 2004 10:46:44 -0500
Hello,
I want to create a new row in the db by copying an existing one.  My
db has an auto incrementing id so I can't simply do insert into cars
select * from cars where id=$id as this throws the primary key error.
How can I do this with out specifying each column?
Thanks!
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] select particular columns in query

2004-12-08 Thread Doug Thompson
The manual is your friend.
You cannot execute the SQL statement you provided because mysql specifically 
disallows it:
http://dev.mysql.com/doc/mysql/en/INSERT_SELECT.html
Same reference, your presumption about auto-increment columns is also wrong.
Doug
blackwater dev wrote:
Hello,
I want to create a new row in the db by copying an existing one.  My
db has an auto incrementing id so I can't simply do insert into cars
select * from cars where id=$id as this throws the primary key error. 
How can I do this with out specifying each column?

Thanks!
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Fwd: [PHP-DB] select particular columns in query

2004-12-08 Thread Ross Honniball
I assume you want to do this within PHP and not native Sql?
Copy sqlSet function below. You could then, for example, code:
// Get data into an associative array by whatever db extraction level you 
are using with query like:
// SELECT * FROM table-name WHERE id = 123
// and put data in assoc array $data. Then...

unset($data['id']);
$query = 'INSERT INTO table-name SET '.sqlSet($data);
// The auto increment will automatically create a new key for you of course.
function sqlSet($assoc_arr, $drop_blanks=false, $quote=') {
$s = '';
$comma = '';
foreach ($assoc_arr as $fld = $val) {
if ($drop_blanks and $val == '') continue; // continue.
$s .= $comma.$fld.'='.$quote.addslashes($val).$quote;
$comma = ',';
}
return $s;
}
Hope this is useful for you. Ross.
Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
list-help: mailto:[EMAIL PROTECTED]
list-unsubscribe: mailto:[EMAIL PROTECTED]
list-post: mailto:[EMAIL PROTECTED]
Delivered-To: [EMAIL PROTECTED]
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=beta; d=gmail.com;
h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding;
b=c6RgUFIIvBsRYq64JatajUSYyyYdWVyJJoWas+jwP/1Ha3StmHkLkMujDX7NSjz3yGKk3nERcTIHXuh6SKs3x2q1uKbjnP/SMbYrezopJjhE8AIfony+D+0Bg3+vvj/2PAZb5So+71WojUcehcR9/Ayv/MTaDp0w0vbdTydari0=
Date: Wed, 8 Dec 2004 10:46:44 -0500
From: blackwater dev [EMAIL PROTECTED]
Reply-To: blackwater dev [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [PHP-DB] select particular columns in query
Hello,
I want to create a new row in the db by copying an existing one.  My
db has an auto incrementing id so I can't simply do insert into cars
select * from cars where id=$id as this throws the primary key error.
How can I do this with out specifying each column?
Thanks!
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
.
. Ross Honniball. JCU Bookshop Cairns, Qld, Australia.
.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php