Re: [PHP] ID value

2001-01-31 Thread Piotr Duszynski

  $sql = "INSERT INTO songs (id,name,url) VALUES
 ('','Foobar','test.php?id=id)";
 
 The id is autoincrement so obviously left blank, yet I'd like to put it into
 the url where id is.
 
 How do I go about dragging back the id even though it is being created (I
 suppose) while the statement is being made -- is it possible or do I have to

Try this:
 
mysql_db_query("
INSERT INTO songs (id,name,url) 
VALUE ('','Foobar','')
";
mysql_db_query($sql);
$id=mysql_insert_id($link);
mysql_db_query=("
UPDATE songs 
SET (url='test.php?id=$id') 
WHERE id=$id
";

This should work but notice that you have to do 2 SQL queries and this
could slow down executing your script if there is some loop. 
-- 

Piotr Duszynski

http://www.softomat.com.pl
http://filmomat.3miasto.pl 
http://www.3miasto.pl

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] ID value

2001-01-23 Thread Sam Masiello

If you are using mysql as your database, you can use mysql_insert_id.

See http://www.php.net/manual/en/function.mysql-insert-id.php for more info
:)

HTH

Sam Masiello
Systems Analyst
Chek.Com
(716) 853-1362 x289
[EMAIL PROTECTED]

 -Original Message-
From:   Robert Morrissey [mailto:[EMAIL PROTECTED]]
Sent:   Tuesday, January 23, 2001 10:17 AM
To: [EMAIL PROTECTED]
Subject:[PHP] ID value

Hi,

I wonder whether anyone can shed some light onto this for me...

Say I have this example insert:

 $sql = "INSERT INTO songs (id,name,url) VALUES
('','Foobar','test.php?id=id)";

The id is autoincrement so obviously left blank, yet I'd like to put it into
the url where id is.

How do I go about dragging back the id even though it is being created (I
suppose) while the statement is being made -- is it possible or do I have to
do something hackish?

Sorry if that's a simple problem...

Regards,

Robert Morrissey



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]