Generate a dynamic grid and populate selected cells. Please help!

girlnextdoor

New Member
I want to generate a grid where people can selected one or more cells and then save them into the database in this format (row,cell):\[code\]18,27 18,28 19,27 19,28\[/code\]Then I want to generate the grid and at the same time mark the cells that is occupied. I have managed to do this (see below) but it does not feel right and I must get the color field from the database aswell so that the cell get the right look (different for each user).This is how I generate the grid and populate it.\[code\]include 'connect.php';$result = mysql_query("SELECT cus_pixels FROM customers");while($row = mysql_fetch_array($result)) { $string .= $row['cus_pixels']." ";}$pixels = explode(' ', $string);$a = 0;while ($a <= 40) { echo "<tr>"; $b = 0; while ($b <= 60) { if (in_array($a.','.$b, $pixels)) { echo '<td class="occupied"></td>'; } else { echo '<td class="pixel"></td>'; } $b += 1; } echo "</tr>";$a += 1;}\[/code\]How can I both generate the grid, populate the cells that are occupied and color them individually. I am really stuck here.Please help!
 
Back
Top