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

 

Link to comment
Share on other sites

<?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>";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.