Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Sat Nov 30, 2002 1:56 pm
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
MeOnTheW3
Forum Commoner
Posts: 48 Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB
Post
by MeOnTheW3 » Sat Nov 30, 2002 4:13 pm
Get the manual at php.net
$last_auto_id = mysql_insert_id($result);
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Sun Dec 01, 2002 10:26 am
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];
?>
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Sun Dec 01, 2002 11:25 am
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