Brendan Nolan
02-11-2003, 10:34 PM
I am working on a PHP/MySql project, and am putting data in that often will only have one unique piece of data - the autoincrement primary key... I then need to get that number and put it into another table... this is how I am currently doing it...
The table looks like this:
rowid | col1 | col2
And the code is like this...
$sql = "INSERT INTO some_table (col1,col2) VALUES ('rowdata1','rowdata2')";
$result = mysql_query($sql);
$sql = "SELECT rowid FROM some_table WHERE col1='rowdata1'";
$result = mysql_query($sql);
$rowid = mysql_result($result,"rowid");
But of course this fails when rowdata1 is the same in more than one column...
What I am asking is: Is there some way of asking MySql what the next autoincrement number is on a particular table.. OR some way for MySql to tell me what number was assigned to the row?
If so how?
Semi Related question... If I drop all of the rows from a table, how can I reset the autoincrement?
The table looks like this:
rowid | col1 | col2
And the code is like this...
$sql = "INSERT INTO some_table (col1,col2) VALUES ('rowdata1','rowdata2')";
$result = mysql_query($sql);
$sql = "SELECT rowid FROM some_table WHERE col1='rowdata1'";
$result = mysql_query($sql);
$rowid = mysql_result($result,"rowid");
But of course this fails when rowdata1 is the same in more than one column...
What I am asking is: Is there some way of asking MySql what the next autoincrement number is on a particular table.. OR some way for MySql to tell me what number was assigned to the row?
If so how?
Semi Related question... If I drop all of the rows from a table, how can I reset the autoincrement?