peter_z Posted March 17, 2006 Share Posted March 17, 2006 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]<?phpinclude '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 POLYGONimagefilledpolygon($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 IMAGEheader('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 ZaniewiczPS, sorry for mixture of English and Polish in the source code. Quote Link to comment https://forums.phpfreaks.com/topic/5157-imagepng-read-colours-from-mysql-match-with-a-patter-long/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.