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 Link to comment https://forums.phpfreaks.com/topic/210271-random-and-unique-values-from-mysql-table-to-html-table/ 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/210271-random-and-unique-values-from-mysql-table-to-html-table/#findComment-1097339 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. Link to comment https://forums.phpfreaks.com/topic/210271-random-and-unique-values-from-mysql-table-to-html-table/#findComment-1097715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.