PDA

View Full Version : highest autoincremented id?


KarateKid[WBC]
Fri 24th May '02, 12:39pm
Hi,

I want to get the latest incremented id in a table. For example the user table. If I delete some useres, and then are new registrations, the userid is of cource not lower, because it is a default autoincremented value in mysql.
So my question. How can I get this last value. With "Select userid FROM user WHERE Max(userid)" I only get the last userid. But if the last userid, issn't the highest value, how can I get it?

Greetings

KarateKid

WingMan
Fri 24th May '02, 4:05pm
Have you tried "Select Max(userid) FROM user"

Or maybe "Select Max(userid)+1 FROM user" to get the next free number

??

KarateKid[WBC]
Sat 25th May '02, 4:22am
This works, if the last user has also the highest userid. But if I deleted maybe the last 50 users and stopped the registration, then the last userid, isn't the last registered user? :(

megahard
Sat 25th May '02, 1:40pm
i dont get y u'd ever wana do that?

explain wot it is u're making and wot ur plan is to do, and i will try and give u a betr solution, cuz that way seems a bit odd.

KarateKid[WBC]
Sat 25th May '02, 1:45pm
hm, you write a diffcult english style for me :eek: :D


maybe, the Moderators of this forum have an idea :)

megahard
Sat 25th May '02, 1:52pm
hehe, didn't realise you were German, I will type correctly for you.

Why do you want to find out what the next ID is going to be?

If you explain what it is you are trying to do overall, then maybe I can provide you with (give you) a better way to do it.

KarateKid[WBC]
Sat 25th May '02, 1:58pm
OK,

I want to findout the next ID because I'll delete 300 members in my vb, because they are 0-poster and not logged in a long time. So I wanted to find out the last ID because I want to put "Active Users:" on top of the vb near "Registrations Ever:". So everyone can see howmany registrations the BB had up to now and how many active users I have.

In another forum, we deleted acutal 20.000 members and have at the moment 6.000. The last Userid is something in 26000 and I wanted to show there. We had 26.000 registrations and 6.000 active users. But I cannot take the MAX(userid) because we stopped the registration and maybe the last user is not the highest ID because, some last users are also deleted :)

I hope u (:D) understand the sence :) :)

Greetings from middle germany (frankfurt)

KarateKid

megahard
Sat 25th May '02, 2:37pm
couldn't you just leave all of the members in the table and say:


//SET YOUR TIME LIMIT
$limit = date("U") - (60*60*24*30);
$result=mysql_query("select * from user");
$total_users=mysql_num_rows($result);
$result=mysql_query("select * from user where posts = 0 AND lastactivity < $limit");
$none_active_users=mysql_num_rows($result);

$active_users=$total_users - $none_active_users;

echo "Active Users: $active_users<br />\nTotal Members: $total_users";




obviously you can change the words and the limit

KarateKid[WBC]
Sat 25th May '02, 3:52pm
yes, thats a possibility I also thought about, but finanlly it it's not that what I want.

Also in the other forum with 26.000 userids this isn't so expressive. :(

eva2000
Sun 26th May '02, 4:34pm
for hacking related questions you'd need to ask at http://vbulletin.org/

in order to use and post in certain forums at vBulletin.org you need to

1. register using the same username and email address you used at vBulletin.com's forums
2. activate and confirm your registration email
3. then enter your forum username at http://www.vbulletin.com/members/vbulletin.org.php to show that you're a licensed vB owner

KarateKid[WBC]
Sun 26th May '02, 4:45pm
I'm still registrated there and have done all these steps ;)

I'll ask there again ;)