|
-
Apr 1st, 2007, 04:30 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Problem selecting a random userid
I'm trying to do a simple thing but run into a problem. All I want to do is pick a random 'userid' and display that on my page.
To come up with random number I do the following:
Code:
$res =& $mdb2->query('SELECT * FROM users');
$num = $res->numRows();
$random = (rand()%$num+1);
i.e. Get the number of rows in my table of users and then pick a random number from it.
However, I have noticed this isn't a good method since my 'userids' are not all sequential. For instance during testing etc. I have deleted id's 3, 4, 5, etc. So if I get random number 3, 4, ,5 etc. I end up with an error.
Is there a better way to select a random 'userid' from the ones which definitely exist?
* Also please note the code above uses PEAR MDB2 Class...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|