Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:39:02+00:00 2026-05-27T15:39:02+00:00

I have a database with the following structure. Index Output 1 1 2 2

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:39:03+00:00Added an answer on May 27, 2026 at 3:39 pm

    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:

    $col = ($i-1)%3;
    $row = floor(($i-1)/3);
    

    And to put them in context, I think something like the below should work:

    while ($db_field = mysql_fetch_assoc($result)) {
        switch($db_field['Result']) {
            case 1: $colour = $blue; break;
            case 2: $colour = $red; break;
            case 3: $colour = $green; break;
        }
        $i = $db_field['index'];
        $col = ($i-1)%3;
        $row = floor(($i-1)/3);
        imagefilledpolygon($image, array(
            $row*10, $col*10,
            $row*10, $col*10+10,
            $row*10+10, $col*10+10,
            $row*10+10, $col*10
        ),4,$colour);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database/table in SQLITE using the following structure CREATE TABLE milestones (
I have a database with the following structure: CREATE TABLE entity ( id SERIAL,
I have the following database structure: CREATE TABLE LookupTable ( PK UNIQUEIDENTIFIER PRIMARY KEY,
I have a SQL database table with the following structure: create table category_value (
I have the following database structure: CREATE TABLE `author` ( `id` int(10) unsigned NOT
I have two database tables with the following structure: actions: action_id int(11) primary key
I have no control over database schema and have the following (simplified) table structure:
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
Say I have a database table like the following: FileID | FileName | FileSize
I have the following database structure: Event table Id - Guid (PK) Name -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.