다음 구조의 데이터베이스가 있습니다.데이터베이스에서 색상 다각형으로 이동 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
내가 (좀 박하 사탕 정면 게임처럼 출력에 따라 그들을 페인트) 사각형의 3X4 매트릭스를 만들 찾고 있어요. 출력이 1이면 출력을 2로, 출력을 2로하면 사각형의 파란색을 그립니다. 출력이 3이면 그 사각형의 녹색을 칠합니다. 사각형은 좀 내가 그리는 모양을 채우기 위해 폴리곤 기능을 사용할 수 있음을 이해
-- -- --
| | | |
-- -- --
| | | |
-- -- --
| | | |
-- -- --
| | | |
-- -- --
(나는 그래픽을 사용하고 제외)과 같이하지만 난 네 좌표의 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);
?>
감사
것 같습니다. 한 번에 12 장 모두를 모으는 것이 더 합리적이지 않습니까? 또한,'imagefilledpolygon ($ image, $ values, 6, $ red'는 닫는'이 없습니다'). – Herbert