Habe folgende Fehlermeldung:Undefined index: bild in C:\xampp\htdocs\map.php on line 96
Was habe ich falsch gemacht oder besser gesagt wie kann ich diese Fehlermeldung umgehen!
Was habe ich falsch gemacht oder besser gesagt wie kann ich diese Fehlermeldung umgehen!
PHP-Code:
class MyMap
{
private $map_width;
private $map_height;
private $field_width_px;
private $field_height_px;
private $window_width;
private $window_height;
private $window_topleft_x;
private $window_topleft_y;
private $fields;
private $x;
private $y;
public function setFields($fields)
{
$this->fields = $fields;
}
public function setField($x, $y, $field)
{
if (($x < 0) || ($y < 0) || ($x >= $this->map_width) || ($y >= $this->map_height)) return false;
$this->fields[$x][$y] = $field;
}
public function getField($x, $y)
{
if (@isset($this->fields[$x][$y])) return $this->fields[$x][$y]; else return false;
}
public function setSize($width, $height)
{
$this->map_width = intval($width);
$this->map_height = intval($height);
}
public function setFieldSize($width_px, $height_px)
{
$this->field_width_px = intval($width_px);
$this->field_height_px = intval($height_px);
}
public function setPosition($x, $y)
{
if ($x < 0) $x = 0;
if ($y < 0) $y = 0;
if ($x >= $this->map_width) $x = $this->map_width - 1;
if ($y >= $this->map_height) $y = $this->map_height - 1;
$this->x = $x;
$this->y = $y;
$this->setWindowPosition($x - ($this->window_width >> 1), $y - ($this->window_height >> 1));
}
public function setWindowSize($width, $height)
{
$this->window_width = intval($width);
$this->window_height = intval($height);
}
public function setWindowPosition($x, $y)
{
if ($x < 0) $x = 0;
if ($y < 0) $y = 0;
if ($x+$this->window_width > $this->map_width) $x = $this->map_width - $this->window_width;
if ($y+$this->window_height > $this->map_height) $y = $this->map_height - $this->window_height;
$this->window_topleft_x = intval($x);
$this->window_topleft_y = intval($y);
}
public function getWindowHtml()
{
$code = '<div id="mymapwindow">';
$window_bottomright_x = ($this->window_topleft_x + ($this->window_width-1) );
$window_bottomright_y = ($this->window_topleft_y + ($this->window_height-1) );
for($y=$this->window_topleft_y; $y <= $window_bottomright_y; $y++)
{
for($x=$this->window_topleft_x; $x <= $window_bottomright_x; $x++)
{
$field = $this->getField($x, $y);
if ($field)
{
$color = $field['color'];
$caption = $field['caption'];
$test = $field['bild'];
}
else
{
$color = '#009933';
$caption = '';
$test = '';
};
$code .= '<div style="float: left; width: '.($this->field_width_px-1).'px; height: '.($this->field_height_px-1).'px; margin-right: 1px; margin-bottom: 1px; background-color: '.$color.'; text-align: center;" title=" '.$caption.' ">('.$x.'|'.$y.')'.$test.'</div>';
};
$code .= '<div style="clear:both;"></div>';
};
$code .= '</div>';
return $code;
}
public function showWindow()
{
echo $this->getWindowHtml();
}
public function getHtml()
{
$code = '<div id="mymap">';
for($y=0; $y < $this->map_height; $y++)
{
for($x=0; $x < $this->map_width; $x++)
{
$field = $this->getField($x, $y);
if ($field)
{
$color = $field['color'];
$caption = $field['caption'];
$test = $field['bild'];
}
else
{
$color = '#009933';
$caption = '';
$test = '';
};
$code .= '<div style="float: left; width: '.($this->field_width_px-1).'px; height: '.($this->field_height_px-1).'px; margin-right: 1px; margin-bottom: 1px; background-color: '.$color.'; text-align: center;" title=" '.$caption.' ">('.$x.'|'.$y.')'.$bild.'</div>';
};
$code .= '<div style="clear:both;"></div>';
};
$code .= '</div>';
return $code;
}
public function show()
{
echo $this->getHtml();
}
};
$map = new MyMap();
$map->setSize(10, 10);
$map->setFieldSize(100, 100); //Feldergrösse
$map->setField(5, 3, array("color"=>'#006699', "caption"=>'Wasser', "bild"=>'<img src="images/bild.png" width="80" height="80" border="0"/>') );
$map->setField(5, 2, array("color"=>'#CCCCCC', "caption"=>'Berge') );
$map->setWindowSize(5, 5); // Sichtfenster
$map->setPosition(5, 2); // Aktuelle Position
$map->showWindow(); // Ausgabe
Kommentar