Jump to content

image.draw and array


georegjlee

Recommended Posts

I am using the line drawing function and want to change the color of the line after each if statement but the line color stays the same after the first if statement. Anybody any ideas.

 

<html>
<head>
<title>First PHP Script</title>
</head>

<?php
function F_SearchArr($arr, $item1, $item2)
{

foreach ($arr as $element => $value) {
if (strcmp($element, $item) == 0) {
return ($arr[$element] = $item2);
}
}

}


//connection to the database
$dbhandle = mysql_connect("localhost", "root", "")
  or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mysql_select_db("waterways", $dbhandle)
  or die("Couldn't open database myDB");

//declare the SQL statement that will query the database

$query = "SELECT t1.waterway_initals, t1.waterway_id, t2.problem_severity  FROM waterways=t1, pending_problems=t2 WHERE t2.waterway_id = t1.waterway_id";

//execute the SQL query and return records
$result = mysql_query($query, $dbhandle);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
?>
<h3 style = "color: blue"> Problems Table</h3>

<table border = "1" cellpadding = "3" cellspacing = "2">

<?php

for ( $counter = 0; $row = mysql_fetch_row($result); $counter++)
{

print( "<tr>");

foreach ( $row as $key => $value )
{
$problem_array[] = "$value";
print	( "<td>$value</td>" );
}

print ( "</tr>" );

}
print ( "</table>" );
//close the connection
mysql_close($dbhandle);

$barrow_array = array(
"BN01"	=> "0",
"BN02"	=> "0",
"BN03"	=> "0",
"BN04"	=> "0",
"BN05"	=> "0",
"BN06"	=> "0",
"BN07"	=> "0",
"BN08"	=> "0",
"BN09"	=> "0",
);

$grand_array = array(
"GC01" => "0",
"GC02" => "0",
"GC03" => "0",
"GC04" => "0",
"GC05" => "0",
"GC06" => "0",
"GC07" => "0",
"GC08" => "0",
"GC09" => "0",
);

$lowerban_array = array(
"LB01" => "0",
"LB02" => "0",
);

$royal_array = array(
"RC01" => "0",
"RC02" => "0",
"RC03" => "0",
"RC04" => "0",
"RC05" => "0",
"RC06" => "0",
"RC07" => "0",
"RC08" => "0",
);



for ( $i = 0; $i < count( $problem_array ); $i++ )
{
switch ($problem_array[$i]){

case "BN":
	$barrow_array[$problem_array[++$i]] = $problem_array[++$i];
break;
case "SN":
	$shannon_array[$problem_array[++$i]] = $problem_array[++$i];
break;
case "RC":
	$royal_array[$problem_array[++$i]] = $problem_array[++$i];
break;
case "GC":
	$grand_array[$problem_array[++$i]] = $problem_array[++$i];
break;
case "LB":
	$lowerban_array[$problem_array[++$i]] = $problem_array[++$i];
break;
}
}
foreach ( $barrow_array as $element => $value )
print ("$element is $value <br />" );

foreach ( $grand_array as $element => $value )
print ("$element is $value <br />" );
?>

<body>
<?php
$im = imageCreateFromJPEG('Ireland_highres10.jpg');
$red = imagecolorallocate($im, 195, 3, 16);
$blue = imagecolorallocate($im, 143, 5, 171);
$yellow = imagecolorallocate($im, 51, 252, 255);
$color1 = imagecolorallocate($im, 255, 25, 55);
imageSetThickness($im, 14);

// BARROW NAVIGATION

// **Credan Head - Carrick-on-Suir**
reset($barrow_array);
$element = key( $barrow_array);
if ($barrow_array[$element] == 0){
$color1 = $blue;
}elseif ($barrow_array[$element] == 1){
$color1 = $red;
}elseif ($barrow_array[$element] == 2){
$color1 = $yellow;
}

imageLine($im, 1617, 2441, 1545, 2409, $color1);
imageLine($im, 1545, 2409, 1493, 2393, $color1);

next($barrow_array);
// Credan Head - New Ross
if ($barrow_array[$element] == 0){
$color1 = $blue;
}elseif ($barrow_array[$element] == 1){
$color1 = $red;
}elseif ($barrow_array[$element] == 2){
$color1 = $yellow;
}
imageLine($im, 1623, 2439, 1605, 2391, $color1);
imageLine($im, 1605, 2391, 1633, 2339, $color1);

// NewRoss - Graiguenamanagh
next($barrow_array);
if ($barrow_array[$element] == 0){
$color1 = $blue;
}elseif ($barrow_array[$element] == 1){
$color1 = $red;
}elseif ($barrow_array[$element] == 2){
$color1 = $yellow;
}
imageLine($im, 1640, 2321, 1657, 2277, $color1);
imageLine($im, 1657, 2277, 1655, 2225, $color1);

imagejpeg($im, 'populated_map.jpg');
imageDestroy($im);
?>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/42095-imagedraw-and-array/
Share on other sites

Archived

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

×
×
  • Create New...

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.