The random profile no longer selects according to UID corrosponding to the random number generated. What it does is generate a random number from the total number of users.
If there are 20 people in the database, counting the built in user #1 I would have to take a random number from 19 as the built in user doesn't count. Now that I have the total number of users I can select from I set up the query to use that random number for the limit argument and not as the UID number. If the random number was 15 the query would select the row 1 total record starting at row 15.
code: if ($palShowregs != 0) { $RandNum = rand(2,$palShowregs); } $query = " SELECT U_Picture,U_Bio,U_Name,U_Username,U_Location,U_Hobbies,U_PicWidth,U_PicHeight FROM w3t_Users WHERE U_Number >= 2 LIMIT $RandNum,1 ";
I have changed this line: $RandNum = rand(2,$palShowregs);
To this also: $RandNum = rand(0,$palShowregs);
as there was no reason to be starting from 2 as the query's format avoided user number 1 anyhow. This should work but it's not efficient as the code you stated earlier.
I have been doing some reading and in MySQL version 3.23 and higher this is a valid query:
SELECT * FROM TableName ORDER BY RAND() LIMIT 1
This is exactly the same query you came up with. I think when I had tried using it last I may have had it set up wrong or something so I'll try it again. I'm pretty sure I have at least 3.23 for a database. (I hope)
Using MySQL to do the random selection is probably more efficient too so this will be the way to go.
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.