私は以下の構造のデータベースを持っています。データベースからカラーポリゴンを取得するPHP
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
私は(ちょっとチックタックつま先のゲームのように、出力に応じてそれらをペイント)の正方形の3×4行列を作成するために探しています。出力が1の場合は正方形の赤を塗ります。出力が2の場合は正方形の青を塗ります。出力が3の場合は正方形の緑を塗ります。四角はちょっと私が描くと図形を埋めるためにポリゴン機能を使用できることを理解
-- -- --
| | | |
-- -- --
| | | |
-- -- --
| | | |
-- -- --
| | | |
-- -- --
(私はグラフィックスを使用してい除く)はこのように見えるが、私は4つの座標の12個の異なるセットを定義する12の配列を記述するか、存在しません私は今、次の
<?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);
?>
をやっている簡単な方法
おかげ
それはあなたが個別DBから各色を得るように見えます。一度に全部12個を集めるのは理にかなっていませんか?また、 'imagefilledpolygon($ image、$ values、6、$ red'は閉じていません') ' – Herbert