Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

How to get the auto-incremented index ?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

How to get the auto-incremented index ?

Postby -[Bl@de Runner]- » Sun Jul 28, 2002 4:21 am

Hi guys,

If someone posts a message in my forum, this code will be executed:

$query = "insert into forum values ('', '$subject, '$iconid', '', '')";
$result = mysql_db_query ("vibDB", $query);

$fIndex = mysql_result ($result, 0, "forumIndex");

$query2 = "insert into forumReplies values ('', '$message', '1', '', '1', 'fIndex')";
$result2 = mysql_db_query ("vibDB", $query2);


In the first query, the first parameter(before the subject) is an auto-incremented field, so this gets filled in automatically.
But I want to get this field back to put it into another table where I need it.
The auto-incremented field is named forumIndex, so I based on the result I want to get it by doing this:

- $fIndex = mysql_result ($result, 0, "forumIndex");


But it gives an error if I do this.
But how can I get the auto-incremented value from this post back ?
-[Bl@de Runner]-
New php-forum User
New php-forum User
 
Posts: 9
Joined: Sun Jun 30, 2002 6:45 am

Postby DoppyNL » Mon Aug 05, 2002 9:55 am

Code: Select all
mysql_insert_id ( [resource link_identifier])

will return the ID generated in an AUTO_INCREMENT field of the previous insert query.

search the php-manual for more details on the function (I use it locally and not online, so can't give you a link rightnow)

Greetz Daan
DoppyNL
 

Postby Jay » Mon Aug 05, 2002 6:29 pm

dvdbinternet wrote:
Code: Select all
mysql_insert_id ( [resource link_identifier])
search the php-manual for more details on the function (I use it locally and not online, so can't give you a link rightnow)


A quick and easy way to search the online manual is to go to http://www.php.net/function_name without the brackets

eg http://www.php.net/mysql_insert_id
Jay
 


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.