Page 1 of 1

SELECT LAST_INSERT_ID()

Posted: Sat Nov 30, 2002 1:56 pm
by phpScott
Arrrggghhhhhhh

I want to get the result back form this query

Code: Select all

$sql="SELECT LAST_INSERT_ID('sponId') FROM sponsor";
$r=mysql_query($sql);
I am doing error checking to make sure I get a result but I can't figure out how to access that result so I can play with the number that should be returned ex. 17 or what ever the last auto-incremented value is.

Any help is great, other suggestions to.

phpScott

Posted: Sat Nov 30, 2002 4:13 pm
by MeOnTheW3
Get the manual at php.net


$last_auto_id = mysql_insert_id($result);

Posted: Sun Dec 01, 2002 10:26 am
by Bill H
Try something like:

Code: Select all

<?php
          $Query = "SELECT LAST_INSERT_ID()";
          $Result = mysql_query($Query, $Link);
          $row = mysql_fetch_array($Result);
          $last_id = $rowї0];  
?>

Bill H

Posted: Sun Dec 01, 2002 11:25 am
by phpScott
thank you Bill H that is just what I needed. I knew that I was doing something silly with my code and sure enough it was.

phpScott