johnmarsella Posted March 21, 2009 Share Posted March 21, 2009 I am currently using a sliding menu script which generates the thumbnails using mysql $row['name'], $row['number'], and $row['image'] (which are: the display name, the ID, and the "base image name" for each entry): //connect, select _db removed $query = sprintf("SELECT * FROM scarf WHERE sold='no'") or die(mysql_error()); $result = mysql_query($query); //check validity code removed while($row = mysql_fetch_array($result)){ $Xmenucontents = "<a href=\"scarf.php?which=".$row['number']."\"><img src=\"scarf/img/pre/".$row['image'].$lastpart."-zoom-pre.jpg\" width=\"100\" height=\"100\" border=\"0\" alt=\"".$row['name']."\"></a> "; echo $Xmenucontents; } where Xmenucontents fills out the info for the sliding menu. What I'd like to do is use Shuffle() to randomize the order of the pictures in the menu each time it is re-generated. It is important also to keep the different values (ie, name, number, and image) all associated together when it is randomized so the links work out right. Using this: while ($row = mysql_fetch_array($sql)) { //how you specify the index of $array here really depends on how it's structured $data[] = $row['name']; shuffle($data); } I can get the names to randomize but I then I am stuck at what to do next. Any help would be appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/150507-solved-using-shuffle-with-mysql_query-results/ Share on other sites More sharing options...
rhodesa Posted March 21, 2009 Share Posted March 21, 2009 randomize it in the query: $query = sprintf("SELECT * FROM scarf WHERE sold='no' ORDER BY RAND()") Link to comment https://forums.phpfreaks.com/topic/150507-solved-using-shuffle-with-mysql_query-results/#findComment-790506 Share on other sites More sharing options...
johnmarsella Posted March 22, 2009 Author Share Posted March 22, 2009 Thanks so much. Works like a charm! Link to comment https://forums.phpfreaks.com/topic/150507-solved-using-shuffle-with-mysql_query-results/#findComment-790662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.