[nycphp-talk] any of you ever wrote a get_next_id function in PHP?
Phil Powell
soazine at erols.com
Mon Oct 6 00:08:19 EDT 2003
function getNewID($fieldName, $tableName) { // INT "METHOD" FOR NON-AUTO-INCREMENT FIELDS
global $dbConn;
$sql = "SELECT MAX($fieldName) FROM $tableName";
$query = mysql_query($sql, $dbConn) or die('Could not perform query: ' . mysql_error());
if (!($row = mysql_fetch_row($query))) return 1;
return $row[0];
}
I'm trying to retrieve the max(ID) from a column that cannot be auto_incremented (since mySQL version on this remote site only allows for tables to have ONE auto_increment field - how stupid), the basic premise is this:
I either return
1) the max ID
2) '1'
How have you guys done it, or what have I missed?
Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20031006/ef26ced8/attachment.html>
More information about the talk
mailing list