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.

Link to comment
Share on other sites

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 :).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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.

Point well made.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.