Select 3 Random values in mysql table

Asked

Viewed 39 times

0

I am trying to make a change to a code that will read in a mysql table the following:

$getmaps = safe_query("SELECT * FROM ".PREFIX."cup_maps WHERE mappack='".$set['mappack']."'");
   while($mp=mysql_fetch_array($getmaps)) {
       $maps.='<option value="'.$mp['map'].'">'.$mp['map'].'</option>'; 
   }

in PHP to select the "Maps" I will have the following:

{
      $select_map = 'Map Option #1<br>';
      $select_map.= '<select class="form-control" name="map1">'.$maps.'</select><br>';
      $select_map.= 'Map Option #2<br>';
      $select_map.= '<select class="form-control" name="map2">'.$maps.'</select>';
  }

In Option 1 and Options 2 will appear a drop down list of the maps that are in the table for the respective "map pack"

What I wanted was that in option 1 and 2 instead of being a drop down list, show a "map" of the table in each of the options.

1 answer

0

Hello,

You can sort the result of your search randomly through the ORDER BY and of the crowd RAND(). Behold:

SELECT * FROM ".PREFIX."cup_maps WHERE mappack='".$set['mappack']."' ORDER BY RAND()

I hope I helped, hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.