mattyvx Posted December 6, 2009 Share Posted December 6, 2009 Hi, I have various users on my site who each have a unique ID some of which have profile pages. What i want to do is dynamically create a hyperlink which when clicked will take me to a random members profile page, the profile page.php retrieves the user ID using $_GET and then displays the details for that user. Not all users have profile pages, if they do the value y is stored in the Profile field of the database. *NOTE i have the profile page up and running its more the random selection bit im after * im trying the following: <?php include 'myconnectionscript.php'; $sql = "SELECT ID FROM Users WHERE Profile = 'y'"; $result = mysql_query($sql); if (!$result) die("Error"); $row = mysql_fetch_array($result); $randID = array_rand(array_flip($row), 1); ?> ..... <a href="profile/profile.php?ID=<?php echo $randID; ?></a> which is only ever giving me one ID value. Any ideas? Im sure its something simple... Link to comment https://forums.phpfreaks.com/topic/184126-selecting-random-numbers-from-results/ Share on other sites More sharing options...
mattyvx Posted December 6, 2009 Author Share Posted December 6, 2009 <?php ... $sql = "SELECT ID FROM Users WHERE Profile = 'y' ORDER BY Rand() LIMIT 1"; $result = mysql_query($sql); if (!$result) die("Error"); $row = mysql_fetch_array($result); $randID = array_rand(array_flip($row), 1); ?> seems to do the trick just nice! Solved Link to comment https://forums.phpfreaks.com/topic/184126-selecting-random-numbers-from-results/#findComment-972157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.