
September 11th, 2003, 07:47 PM
|
|
Contributing User
|
|
Join Date: Apr 2003
Posts: 187
Time spent in forums: < 1 sec
Reputation Power: 6
|
|
|
mt_rand and userid problem
Okay so I have a database with a table users, and the first entry is an auto inc primary key userid. I then have a page which selects random users this way:
PHP Code:
$randcount = mysql_query("SELECT COUNT(*) FROM users WHERE pending != 'yes'");
$randmax = mysql_result($randcount, 0, 0);
$randnum = mt_rand(1,$randmax);
I then make a picture display based on userid = $randnum.
But the problem is when a user is deleted, the database continues to add users AFTER the last users id; ie, user 6 deletes himself, user 7 is added; it doesn't replace user 6. THEN the random num is between 1-7, but six doesn't exist. So if six OR seven show up, it won't work (I'm assuming seven, I don't knwo why this would be true, but the other entries seem to return nothing also). My table is good, and works fine for other things. How can I fix this? Is there a way maybe to make the table auto inc depending on last userid? I think it is a major propblem otherwise...
thanks!
__________________
hey it's the CHARKING
|