Jump to content

Random and unique values from MySQL table to html table?


veroaero

Recommended Posts

Hello,

 

I need some help. Say that I have a list in my MySQL database that contains elements "A", "S", "C", "D" etc... Now, I want to generate an html table where these elements should be distributed in a random and unique way while leaving some entries of the table empty, see the picture below. But, I have no clue how to do this... Any hints?

 

phpHelp.jpg

 

Thanks in advance,

Vero

 

<?php
$chararr = array("A","S","D","F","K","Z","M","P","Y"); //populate this array from mysql table
$tablerow=5;
$tablecol=5;
$totcell=($tablecol*$tablerow);
for($x=count($chararr);$x<$totcell;$x++){
      $chararr[]=" ";
}
shuffle($chararr);
echo "<table border=\"1\">";
$pointer = 0;
for($i=0;$i<$tablerow;$i++){
      echo "<tr>";
      for($j=0;$j<$tablecol;$j++){
            echo "<td>".$chararr[$pointer++]."</td>";
      }
      echo "</tr>";
}
echo "</table>";

?>

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.