Jump to content

[SOLVED] How to check id


nathanmaxsonadil

Recommended Posts

Wow...you just love to close and open this topic.

 

Just do this to save all the troubles:

 

In your script where you want to insert the id, put this

 

$query = mysql_query("SELECT * FROM table");

$row = mysql_num_rows($query) + 1;

 

$row will have the next available id number.

No, don't take the easy way out, it'll prove terribly inefficient.  What if you delete a record so you only have 6 records but the latest id is 7? It'll try to add 7 again and result in an error.

 

http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

 

phpMyAdmin should deal with it for you.  It works best for primary keys, and I'm assuming iD will be your primary key :).

Well for my method, it's not hard to fix the id numbers after you deleted something. A for/while loop should fix everything.

 

It's like re-updating the id column.

 

What if you had thousands of users?  It's a big request on the server every time someone deletes an account.  Also, a solution has already been provided my DBMS's, so 'why reinvent the wheel'.  I hear that said all over these forums.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.