webForumDet fria alternativet

Efter INSERT få fram Id?

4 svar · 264 visningar · startad av GrodanBoll

GrodanBollMedlem sedan sep. 2001788 inlägg
#1

Hej hej :)

Jag undrar hur man får fram den nya postens nummer efter det att man har insert:at en ny post?
Jag använder MySql

/Grodan

SkarreMedlem sedan apr. 20012 427 inlägg
#2

int mysql_insert_id ( [resource link_identifier])

mysql_insert_id() returns the ID generated for an AUTO_INCREMENT column by the previous INSERT query using the given link_identifier. If link_identifier isn't specified, the last opened link is assumed.

mysql_insert_id() returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call mysql_insert_id() immediately after the query that generates the value.

Kent.JMedlem sedan aug. 2001153 inlägg
#3

Fel forum btw ;)

Denna går också o använda

Also note that the value of the SQL LAST_INSERT_ID() function always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries because the value of that function is maintained in the server.

GrodanBollMedlem sedan sep. 2001788 inlägg
#4

RTFM? ;)
Tackar :bire

mahedelMedlem sedan juli 2002105 inlägg
#5

ett annat script...

jag använder mig av detta när jag vill veta id:t från senaste posten...

$open = mysql_connect ("localhost", "$dbu","$dbp");
$sql = "SELECT id FROM tabell order by id desc limit 1";
$result = mysql_db_query("databasnamn","$sql");

while($row=mysql_fetch_array($result)){
$senaste_id = $row['id'];
}
130 ms totalt · 3 externa anrop · v20260731065814-full.3ab8d573
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
127 ms — hämta tråd, inlägg och bilagor (db)