Jump to content

Archived

This topic is now archived and is closed to further replies.

peter_z

Imagepng, read colours from MySQL, match with a patter *LONG

Recommended Posts

Hello to all!

I am totally stuck with my problem at the moment and don't even know what to type in google that would help me to solve it. So any help will be greatly appreciated!! Please add your comments!

I have a php page, called teeth.php. Here is the source code sample that I need to ask about:

[code]
<?php
include 'config.php';

    $z1sql = "SELECT
        *
        FROM
        `z1`
        WHERE
`p_id` = '".$_GET['p_id']."'";

    $result = mysql_query($z1sql)
    or die("Invalid query: " . mysql_error());
    while( $row = mysql_fetch_array($result, MYSQL_ASSOC) )
    {?>
    <html>
    <head>
    </head>
    <body>
<?


if($row['stan'] == "1") {
echo "<img src=\"./tooth.png\">";
}
if($row['stan'] == "2"){
    
    if($row['wleft'] != "0"){
        
        if($row['wleft'] == "1")
        {
        $wleft = "?typ=1&wherel=wleft";
        #echo "<img src=\"./tooth.php?typ=1&where1=wleft\">";
        }
        if($row['wleft'] == "2")
        {
        $wleft = "?typ=2&wherel=wleft";
        #echo "<img src=\"./tooth.php?typ=2&where1=wleft\">";
        }
       //....the above goes up to typ=8
    }
    if($row['wright'] != "0"){
        
        if($row['wright'] == "1")
        {
        $wright = "&typ=1&wherer=wright";
        #echo "<img src=\"./tooth.php?typ=1&where1=wright\">";
        }
        if($row['wright'] == "2")
        {
        $wright = "&typ=2&wherer=wright";
        #echo "<img src=\"./tooth.php?typ=2&where1=wright\">";
        }
       //....the above goes up to typ=8
    }


}

echo "<img src=\"./tooth.php$wleft\">"; //THIS CAN DRAW TWO REGIONS, BUT THE SAME COLOUR

?>
    <?php
    }
    ?>
[/code]


The script is quite easy to understand. It connects to a database, reads row where `p_id` = '".$_GET['p_id']"' and then depending on what values it finds, a specific data is sent to script named tooth.php, which displays an image with "on the fly" shapes. Here comes the code:

[code]
<?php
$link = mysql_connect('localhost', '****', '****');

mysql_select_db('gabinet', $link) or die(mysql_error());
mysql_query("set names 'utf8'");

$wybkol = "SELECT
        *
        FROM
        `wypelnienia` //there are 8 different types of tooth fittings in this table together with RGB columns, which define specific colours.
        WHERE
`typ` = '".$_GET['typ']."'";

    $result = mysql_query($wybkol)
    or die("Invalid query: " . mysql_error());
    while( $row = mysql_fetch_array($result, MYSQL_ASSOC) )
    {?>
<?
#takes image
$image = imagecreatefrompng("./tooth.png");

#tooth fitting upper part
$wup = array(
    33, 7,
    26, 14,  
    15, 14,
    8, 7  
    );

#wypelnie zeba right
$wright = array(
    35, 44,
    28, 37,
    28, 15,
    35, 8  
    );

#wypelnienie zeba left
$wleft = array(
    7, 44,
    7, 9,  
    14, 16,
    14, 37
    );

#wypelnienie zeba down
$wdown = array(
    9, 45,
    16, 38,
    26, 38,
    33, 45  
    );
#wypelnienie zeba center
$wcenter = array(
    17, 17,
    25, 17,  
    25, 35,
    17, 35  
    );
#border down
$bdown = array(
    0, 52,
    4, 48,
    38, 48,
    42, 52
    );
#border left
$bleft = array(
    0, 52,
    4, 48,
    4, 4,
    0, 0
    );
#border up
$bup = array(
    0, 0,
    4, 4,
    38, 4,
    42, 0
    );
#border right
$bright = array(
    42, 0,
    38, 4,
    38, 48,
    42, 52
    );


#kolory //the script
$color = imagecolorallocate($image, $row['r'], $row['g'], $row['b']);

#border //DON'T WORRY about this!
#imagefilledpolygon($image, $bdown, 4, $color);
#imagefilledpolygon($image, $bleft, 4, $color);
#imagefilledpolygon($image, $bright, 4, $color);
#imagefilledpolygon($image, $bup, 4, $color);

#zab //DRAWING A POLYGON
imagefilledpolygon($image, $$_GET['wherel'], 4, $color);
imagefilledpolygon($image, $$_GET['wherer'], 4, $color);
imagefilledpolygon($image, $$_GET['whereu'], 4, $color);
imagefilledpolygon($image, $$_GET['whered'], 4, $color);
imagefilledpolygon($image, $$_GET['wherec'], 4, $color);
//A TOOTH CAN HAVE 5 DIFFERENT FITTING REGIONS!!


#prezentacja obrazka //DISPLAYING AN IMAGE
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

<?
}
?>
[/code]


Now, everything works perfect with displaying the single colours,image etc, BUT there is a problem. A tooth can have 5 different fitting regions!! As you have seen in the teeth.php, the script sends only one fitting region. It is not a problem to send more, but the tooth.php script will not process them properly!!
You probably know why. It is because it GETs the 'typ' value and looks in the table for it. It doesn't GET two 'typ's or 8 as it has to be done in the final stage. (There will be 32 teeth in the final stage, so any help regarding code optimazation will be greatly appreciated!)


As I have written above, I am stuck with this problem, don't know where to go, REALLY.
Please give me any piece of advice about how to put this to work. Any additional hints, as how to optimise the code, would be apprecieted very much!!

If you have questions, please ask.

Ok, some real life examples:
[a href=\"http://www.eldora.pl/test/teeth.php?p_id=3\" target=\"_blank\"]Teeth.php at work[/a]
[a href=\"http://www.eldora.pl/test/tooth.php?typ=3&wherel=wleft\" target=\"_blank\"]tooth.php displayin one polygon[/a]
[a href=\"http://www.eldora.pl/test/tooth.php?typ=3&wherel=wleft&wherer=wright\" target=\"_blank\"]tooth.php displayin two polygons[/a]

I cannot get different colours to work, any ideas, please help!!

Best wishes,

Piotr Zaniewicz

PS, sorry for mixture of English and Polish in the source code.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.