veroaero Posted August 10, 2010 Share Posted August 10, 2010 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? Thanks in advance, Vero Quote Link to comment Share on other sites More sharing options...
abdfahim Posted August 10, 2010 Share Posted August 10, 2010 <?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>"; ?> Quote Link to comment Share on other sites More sharing options...
veroaero Posted August 10, 2010 Author Share Posted August 10, 2010 Thank you very much! It works as a charm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.