I have a database with the following structure.
Index Output
1 1
2 2
3 1
4 1
5 3
6 1
7 2
8 1
9 3
10 2
11 2
12 3
I am looking to create a 3X4 matrix of squares (kinda like a tic tac toe game and paint them according to the output). So if the output is 1 I’ll paint that square red, if the output is 2, I’ll paint that square blue and if the output is 3 I’ll paint that square green. The squares kinda look like this (except I’m using graphics)
-- -- --
| | | |
-- -- --
| | | |
-- -- --
| | | |
-- -- --
| | | |
-- -- --
I understand that I can use polygon function to draw and fill shapes but do I write 12 arrays defining 12 different sets of four coordinates or is there a simpler way
I am doing the following right now
<?php
$user_name = "root";
$password = "pass";
$database = "db";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$blue = imagecolorallocate($image, 0, 0, 255);
$red = imagecolorallocate($image, 255, 0, 0);
$green = imagecolorallocate($image, 0, 255, 0);
$image = imagecreatetruecolor(400, 300);
$col_poly = imagecolorallocate($image, 255, 255, 255);
if ($db_found) {
for ($i = 0 ; $i<=12 ; $i=$i+1) {
$SQL = "SELECT * FROM table1 where index like " . $i
$result = mysql_query($SQL);
while ($db_field = mysql_fetch_assoc($result)) {
if ($db_field['Result'] == 1) { // and similarly for blue and green
imagepolygon($image, array(
0, 0,
0, 10,
10, 10,
10, 0
),
4,
$col_poly);
imagefilledpolygon($image, $values, 6, $red
}
// and so on for others
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
Thanks
A little bit of maths should help! If we calculate what column and row a given number should appear in then the rest should be fairly simple. These two lines should help:
And to put them in context, I think something like the below should work: