Jump to content

Modifying Newly Inserted Values


ThePsion5
 Share

Recommended Posts

Hi Guys,I'm writing a PHP function that inserts multiple values into a MySQL database, and then creates a new entry in a different table that references the freshly inserted values. I can't remember how to do this, however. My insert statement looks something like this:

INSERT INTO Clients VALUES(0, 'name','site'), VALUES(0, 'name2', 'site2'), VALUES ('name3', 'site3');

Should I break the queries into individual inserts and then create the reference using New.ID or is there a better way? Thanks in advance!-Sean

Link to comment
Share on other sites

You did it kind of wrong.. I would set it up this way:

INSERT INTO `Clients`   VALUES (0, 'name', 'site')  VALUES (0, 'name2', 'site2')  VALUES (0, 'name3', 'site3');

try that..

Link to comment
Share on other sites

You did it kind of wrong.. I would set it up this way:
INSERT INTO `Clients`   VALUES (0, 'name', 'site')  VALUES (0, 'name2', 'site2')  VALUES (0, 'name3', 'site3');

try that..

Hah, that does help, doesn't it? What I'm still wondering is if I can get the IDs of the newly inserted values without having to use a select statement to find them again. As in can I avoid having to use a statement like the following:
SELECT ID FROM 'Clients' WHERE Name='name' AND site='site' OR Name='name2' AND site='site2' (and so on...)

Is it possible for me to use NEW here, as in a much easier statement like this one:

select ID from NEW

Link to comment
Share on other sites

you could do thisMS SQL

SELECT TOP 3 * FROM Clients ORDER BY ID DESC

MySql

SELECT * FROM Clients ORDER BY ID DESC LIMIT 3

This only works if ID is unique and increments with each new entry.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...