This is a discussion on is there a way to 'insert and fetch value'? within the MySQL Database forums, part of the Database Forums category; I am writing a DB like this: --------------------------------------------------------------------- | id (auto_incremented filed) | foo | bar | --------------------------------------------------------------------- $sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am writing a DB like this:
--------------------------------------------------------------------- | id (auto_incremented filed) | foo | bar | --------------------------------------------------------------------- $sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', '$string_2')"; mysql_query($sql_query, $db_handle); //how can I get id for the above inserted entry? is that possible I get it with a single mysql instruction? since each time I write a record into mysql, 'id' is incremented, how can I get the id that an insertion corresponds to (can I get it with a single mysql instruction)? Thanks, |
|
|||
|
On Fri, 20 Jul 2007 09:31:58 +0200, newbie <mitbbsmj@yahoo.com> wrote:
> I am writing a DB like this: > --------------------------------------------------------------------- > | id (auto_incremented filed) | foo | bar | > --------------------------------------------------------------------- > > $sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', > '$string_2')"; > mysql_query($sql_query, $db_handle); > //how can I get id for the above inserted entry? is that possible I > get it with a single mysql instruction? > > > since each time I write a record into mysql, 'id' is incremented, > how can I get the id that an insertion corresponds to (can I get it > with a single mysql instruction)? Please do not multi- and/or crosspost. Answered in comp.lang.php -- Rik Wasmus |
|
|||
|
Rik wrote:
> On Fri, 20 Jul 2007 09:31:58 +0200, newbie <mitbbsmj@yahoo.com> wrote: > >> I am writing a DB like this: >> --------------------------------------------------------------------- >> | id (auto_incremented filed) | foo | bar | >> --------------------------------------------------------------------- >> >> $sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', >> '$string_2')"; >> mysql_query($sql_query, $db_handle); >> //how can I get id for the above inserted entry? is that possible I >> get it with a single mysql instruction? >> >> >> since each time I write a record into mysql, 'id' is incremented, >> how can I get the id that an insertion corresponds to (can I get it >> with a single mysql instruction)? > > Please do not multi- and/or crosspost. > Answered in comp.lang.php > --Rik Wasmus Actually, cross-posting is good. Multi-posting is not. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
On Fri, 20 Jul 2007 13:04:52 +0200, Jerry Stuckle
<jstucklex@attglobal.net> wrote: > Rik wrote: >> On Fri, 20 Jul 2007 09:31:58 +0200, newbie <mitbbsmj@yahoo.com> wrote: >> >>> I am writing a DB like this: >>> --------------------------------------------------------------------- >>> | id (auto_incremented filed) | foo | bar | >>> --------------------------------------------------------------------- >>> >>> $sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', >>> '$string_2')"; >>> mysql_query($sql_query, $db_handle); >>> //how can I get id for the above inserted entry? is that possible I >>> get it with a single mysql instruction? >>> >>> >>> since each time I write a record into mysql, 'id' is incremented, >>> how can I get the id that an insertion corresponds to (can I get it >>> with a single mysql instruction)? >> Please do not multi- and/or crosspost. >> Answered in comp.lang.php >> --Rik Wasmus > > Actually, cross-posting is good. Multi-posting is not. > Crossposting is the lesser of two evils. Not good except for a few rare exceptions. -- Rik Wasmus |
|
|||
|
On Jul 20, 4:04 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Rik wrote: > > On Fri, 20 Jul 2007 09:31:58 +0200, newbie <mitbb...@yahoo.com> wrote: > > >> I am writing a DB like this: > >> --------------------------------------------------------------------- > >> | id (auto_incremented filed) | foo | bar | > >> --------------------------------------------------------------------- > > >> $sql_query = "INSERT INTO `table` (`foo`, `bar`) VALUES ('$string_1', > >> '$string_2')"; > >> mysql_query($sql_query, $db_handle); > >> //how can I get id for the above inserted entry? is that possible I > >> get it with a single mysql instruction? > > >> since each time I write a record into mysql, 'id' is incremented, > >> how can I get the id that an insertion corresponds to (can I get it > >> with a single mysql instruction)? > > > Please do not multi- and/or crosspost. > > Answered in comp.lang.php > > --Rik Wasmus > > Actually, cross-posting is good. Multi-posting is not. Sorry, I did multi-posting (accidentally) because the first post was not shown for more than 10 minutes (during which time periods I posted the 2nd). Sorry about that, and by the way, can anyone explain a bit why this happened? Thanks > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstuck...@attglobal.net > ================== |