Jump to content
php.lv forumi

next Autoindex


archux

Recommended Posts

Sveiki, vai ir kaut kādā veidā iespējams izvilkt no datubāzes next Autoindex vai arī pēdējo tipa last index no datubāzes? Ja jā kāds tas izvelkamais parametrs izskatītos un kā ar to darboties?

Link to comment
Share on other sites

atradu pats, ir divi varianti:

 

$q = mysql_query("show table status from DATABASE like 'TABLE'") or die(mysql_error());

print mysql_result($q, 0, 'Auto_increment'); // which prints the next autoincrement value

 

un otrs:

 

$sql = 'SELECT MAX(thread_id) AS max_thread_id FROM threads';

 

this creates a variable for an SQL query that gets the highest value in the "thread_id" column using the MAX() aggregate function and stores it in a varibale called "max_thread_id".

 

$result = mysql_query ($sql);

 

...runs the query and stores the result set as $result

 

$array = mysql_fetch_assoc ($result);

 

...spools the result set into an associative array

 

extract ($array);

 

...extracts out the array element as a global variable so now you have a variable $max_thread_id that is the last thread_id that was inserted. All of the above code can be done in a single line:

 

extract (mysql_fetch_assoc (mysql_query ("SELECT MAX(thread_id) AS max_thread_id FROM threads")));

 

then add 1 to that varibale:

 

$next_autoindex = $max_thread_id + 1;

 

$next_autoindex is the value of whatever the next insert auto_incerement will be.

 

vairāk info te: http://www.phpbuilder.com/board/archive/in...t-10218213.html

Link to comment
Share on other sites

extract (mysql_fetch_assoc (mysql_query ("SELECT MAX(thread_id) AS max_thread_id FROM threads")));

then add 1 to that varibale:

$next_autoindex = $max_thread_id + 1;

$next_autoindex is the value of whatever the next insert auto_incerement will be.

Kaut kā tas viss izskatās traki aizdomīgi gadījumā, ja ar to sistēmu strādā vairāk nekā 1 lietotājs...

 

Gints Plivna

http://datubazes.wordpress.com

Link to comment
Share on other sites

×
×
  • Create New...