dachshund Posted July 29, 2009 Share Posted July 29, 2009 ...just goes to a random id number. for example on the site there are interviews. how can i make a link that will just take you to a random interview? ta. Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 It's definitely possible. $random_row = mysql_fetch_row(mysql_query("SELECT * FROM YOUR_TABLE ORDER BY RAND() LIMIT 1")); Quote Link to comment Share on other sites More sharing options...
dachshund Posted July 30, 2009 Author Share Posted July 30, 2009 ok and how about if the limit was 6, is it possible to tell it to not post the same id twice? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 ok and how about if the limit was 6, is it possible to tell it to not post the same id twice? you can store the id in global array, and then do a check to see if that ID has already came up. thats how i understood ur question Quote Link to comment Share on other sites More sharing options...
dachshund Posted July 30, 2009 Author Share Posted July 30, 2009 how can i store it in global array? i'm not really used to working with it. thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 how can i store it in global array? i'm not really used to working with it. thanks http://ca.php.net/manual/en/language.variables.scope.php Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 30, 2009 Share Posted July 30, 2009 I don't think a global array is necessary for grabbing unique random records... a variable within function scope should be sufficient. You could also give this a try: $random_row = mysql_fetch_row(mysql_query("SELECT DISTINCT * FROM YOUR_TABLE ORDER BY RAND() LIMIT 1")); Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 I don't think a global array is necessary for grabbing unique random records... a variable within function scope should be sufficient. You could also give this a try: $random_row = mysql_fetch_row(mysql_query("SELECT DISTINCT * FROM YOUR_TABLE ORDER BY RAND() LIMIT 1")); I thikn he said everytime he has a random id generated, the same one doesnt come up next time he runs the script right? lol? Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 30, 2009 Share Posted July 30, 2009 That wouldn't really be the definition of random, but I see what you're saying Quote Link to comment Share on other sites More sharing options...
dachshund Posted July 30, 2009 Author Share Posted July 30, 2009 actually it's fine. with the code I have it works. thanks for all your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.