is there a way to 'insert and fetch value'?

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 ('$...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-20-2007
newbie
 
Posts: n/a
Default is there a way to 'insert and fetch value'?

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,

Reply With Quote
  #2 (permalink)  
Old 07-20-2007
Rik
 
Posts: n/a
Default Re: is there a way to 'insert and fetch value'?

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
Reply With Quote
  #3 (permalink)  
Old 07-20-2007
Jerry Stuckle
 
Posts: n/a
Default Re: is there a way to 'insert and fetch value'?

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
==================
Reply With Quote
  #4 (permalink)  
Old 07-20-2007
Rik
 
Posts: n/a
Default Re: is there a way to 'insert and fetch value'?

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
Reply With Quote
  #5 (permalink)  
Old 07-20-2007
Geoff Berrow
 
Posts: n/a
Default Re: is there a way to 'insert and fetch value'?

Message-ID: <uN-dnSz3UpAeCz3bnZ2dnUVZ_tXinZ2d@comcast.com> from Jerry
Stuckle contained the following:

>Actually, cross-posting is good.


s/is/can be

--
Regards,

Geoff Berrow
Reply With Quote
  #6 (permalink)  
Old 07-20-2007
newbie
 
Posts: n/a
Default Re: is there a way to 'insert and fetch value'?

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
> ==================



Reply With Quote
  #7 (permalink)  
Old 07-20-2007
Rik
 
Posts: n/a
Default Re: is there a way to 'insert and fetch value'?

> can anyone explain a bit
> why this happened?


Yes: You use Google Groups. Google Groups is bad. Try a nntp server and a
news client.
--
Rik Wasmus
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:54 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0