two questions on generating a random user
$frm=mysql_query("SELECT users.gender,stats.dob,stats.sex_pref,stats.mar_stat,stats.country FROM users,stats WHERE users.uid=stats.uid AND users.uid=
'obviously that's imcomplete. what i'm not sure is how to randomly generate a user id number. rand() takes a seed, and i'm not going to know how many users there are prior to running this select. so i'm not sure how to randomly get a valid number (there will probably be holes as people delete from the site, etc.
also, once i have the array will it be $array['table.field'] or $array['field'] to access the array?
i haven't tried to get things form multiple tables before.
thnx in advance
-Josh
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 19:49 — 10th September 2003.
He has: 4,048 posts
Joined: Aug 2000
SELECT * FROM users ORDER BY rand() LIMIT 1
ShaneS posted this at 20:51 — 10th September 2003.
They have: 93 posts
Joined: Jun 2003
Not sure why you want to generate a random ID, and not a somewhat sequential index with AUTO_INCREMENT , this will eliminate the HUMAN error aspect and always generate a unique ID.
In answer to your query results: $result['fieldname']
?? This will only select a random user, if he uses that ID whats to say its not 3, and someone is #4, then he would be given an error is he made it a unique field, or he would have two entries under the same ID.
To get your last highest ID
SELECT id FROM users ORDER BY id DESC LIMIT 1
[Design Alpha] -Web Services : Design,Hosting,Advertising,Software
Ask about custom pricing on hosting!!
Site Assets: [UltraGaming.com] [Blades of Warcraft]
m3rajk posted this at 00:05 — 11th September 2003.
They have: 461 posts
Joined: Jul 2003
shane: i have a database with user id numbers assigned when you sign up.
some people may delete, some may be deleted. this leaves holes.
for the front page i want to seelct a user at random and pull some information for a section.
so i want to pull a randome user between 1 and an unknown maximum.
i'm hoping to find a way to do this so that it'll change the user displayed with each load of the index.
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Mark Hensler posted this at 00:19 — 11th September 2003.
He has: 4,048 posts
Joined: Aug 2000
SELECT users.gender,stats.dob,stats.sex_pref,stats.mar_stat,stats.country
FROM users
INNER JOIN stats ON users.uid=stats.uid
ORDER BY rand()
LIMIT 1
Mark Hensler
If there is no answer on Google, then there is no question.
m3rajk posted this at 01:00 — 11th September 2003.
They have: 461 posts
Joined: Jul 2003
i think i understand what's happening. i'd like to make sure i do understand what's happening there.
selects the feilds i want to display
means to search by the users table
means to synchronise based on the uid fields
makes it randomly take the users on the ... for lack of a better way to think of it, the temporary table it made
makes it take just one of them.
i've never used a join before, or the rand function, which is why i want to make sure i understand what's going on
sorry about asking more questions, it's just how i do things with programming/scripting. when i ask for help, if i'm using things that are new to me i break it down and verify that i'm understanding each part, so that i know i'll be learning what's goingon correctly. then i can help others in the future
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.