View Single Post
  #3 (permalink)  
Old 02-26-08, 20:03
Germaris Germaris is offline
Registered User
 
Join Date: Apr 2004
Location: Canada
Posts: 57
Thanks for your reply and for the logic of the ways you explored.
You are right.
Except for the first paragraph because you are not aware of my needs (I need to get the next auto_increment value because I need to display this value as it will be also the number of the order/bill BEFORE the customer click to confirm its purchase)

Quote:
Originally Posted by healdem
you can't
This is not true.
Code:
<?php 
$res = mysql_query("SHOW TABLE STATUS LIKE '$tablename'");  
if ($res && mysql_num_rows($res)) {  
    $row = mysql_fetch_assoc($res);  
    $next_autoid = $row["Auto_increment"];  
} else { 
    die("error!"); 
} 
echo "next auto_increment value for `tablename` is ", $next_autoid; 
?>
Quote:
Originally Posted by healdem
what you can do is get the last value using the appropriate php function, if you are using MySQL it's mysql_insert_id
It will be a good solution and I think I’ll use it...

Quote:
Originally Posted by healdem
you can guess it will almost certainly be that +1, however in a multi user system, short of attempting to secure a table lock you cannot guarantee what the next autonumber ID will be. In any event an autonumber column should have no meaning or value outside the system itself.
That’s really true!

Quote:
Originally Posted by healdem
just out of curiosity: why would you want to know what the next ID is going to be?
See the beginning of this post...

Your post makes sense and, for sure, I’ll use the solution mentioned in the second quote.

Thanks again for the time you dedicated to help me!

Best regards,
Gerry
Reply With Quote