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. Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/ 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")); Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886230 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? Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886832 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 Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886840 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 Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886856 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 Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886862 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")); Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886864 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? Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886865 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 Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886868 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! Link to comment https://forums.phpfreaks.com/topic/168028-solved-is-it-possible-to-make-a-link-that/#findComment-886893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.