如何在while循环中保持循环?

I have a table with five rows for example, and my while loop will display the five rows for me as per normal. I‘m trying to get the loop to keep looping records until let's say $count = 12. I want to start the counter at 0 and it will end at 12. So, I pretty much want the loop to keep showing the same records randomly until it shows me 12 or so results and then stops.

Simple as while ($a != 12)

$counter = 0;

while ($counter != 12) {
    // Do stuff
    $counter = rand(0, 24);
}

I'd read the records into an array, and then loop N times displaying a random record from it.

// Read the query to an array
$data = array();
while (($row = mysql_fetch_array($result, MYSQL_ASSOC)) !== false){
  $data[] = $row;
}
$num_db_rows = count($data);


// Display random rows:
$NUM_DISPLAY_ROWS = 12; // Or any other number:
for ($i = 0; $i < $NUM_DISPLAY_ROWS; ++$i) {
    $row = $data[rand(0, $num_db_rows - 1)];
    // Display this row...
}