Steve Lefevre wrote:
I'm designing a user database for PHP 4 and MySQL 3.32 or whatever.

Users enter a class and it's workshops for their students.

The 'Class' table has  fields 'Name' and 'ID'.
ID is the primary key and its an auto-incremented integer

The 'Workshop' table has a field ID, Number, ClassID, Date, etc.

The 'ClassID' should be the value of the ID field of its parent class.

After I use an insert to create the Class data, how do I get the appropriate
ClassID for the 'Workshop' table inserts? I could assume to use the very
latest one, but that *might* break, as this is a multi-user database.

Is there a way I can issue an insert statement, and get a return of the ID
value it got?
You can remove auto-increment and write a function that returns the max id like

function getMaxId() {
$sql= mysql_query("select max(ID) as max_id from Class");
$rs = mysql_fetch_array($sql);
$id = $rs["max_id"];
$id++;
return $id;
}

$ID = getMaxId();

Giannis




---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to