Jump to content


Photo

auto_increment - finding value assigned*solved*


  • Please log in to reply
3 replies to this topic

#1 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 06 July 2006 - 09:24 AM

Ok, i am inserting a row into a mysql table and the field `id` is automatically given a number as it is set to auto-increment.

After performing the insert, is there any way to find out what number was actually put into the id field?

I hope that makes sense.

Thanks in advance.

#2 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 06 July 2006 - 09:39 AM

with mysql you can use the insert_id function, which can be found here - in the mysql documentation on php.net.

http://uk.php.net/ma...l-insert-id.php

If you have any trouble with it working, then I am sure others will be able to help - just beware that it will return the last insert id, so if you are running two inserts (info into two tables) it will return the id for the second table, NOT the first.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 July 2006 - 09:41 AM

You'll want to use a function called mysql_insert_id

#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 06 July 2006 - 09:44 AM

Thanks very much to both of you, that is exactly what i want.

Thanks again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users