Jump to content

[SOLVED] Using Shuffle() with mysql_query results


johnmarsella

Recommended Posts

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>&nbsp";

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!

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.