Ich schaffe es leider nicht, sämtliche Datensätze der Datenbank an das Javascript zu übergeben. Mit dem Quellcode von Netzwolf und ein wenig experimentieren habe ich es zumindest geschafft, den ersten Datensatz zu übergeben.
<?php
#===============================================================================
# Database config
#===============================================================================
// "clean" names only! there is *no* sql-escaping.
include ("login/login.txt");
#===============================================================================
# Database
#===============================================================================
#-----------------------------------------------------
# Connect to server
#-----------------------------------------------------
if (!@mysql_connect ($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASSWORD)) die(mysql_error());
#-----------------------------------------------------
# Select database
#-----------------------------------------------------
if (!@mysql_select_db ($MYSQL_DATABASE)) die(mysql_error());
#-----------------------------------------------------
# Select row
#-----------------------------------------------------
# Lese alle Felder in *einem* Request. Dann passen die Werte auch zusammen.
# Und garantiere maximal 1 Ergebnis.
$query = "SELECT positionlat, positionlon, meldung FROM sichtungen LIMIT 1";
$result= @mysql_query ($query);
if (!$result) die(mysql_error());
#-----------------------------------------------------
# Extrahiere Felder
#-----------------------------------------------------
if (mysql_num_rows($result) !=1) { die("Nix oder zuviel gefunden."); }
list ($positionlat, $positionlon, $meldung) = mysql_fetch_row($result);
#-----------------------------------------------------
# aus dem Feldern was gebastelt
# ACHTUNG!!! wenn Quotezeichen im Text enthalten sein koennen, quoten!
#-----------------------------------------------------
$text = "{$meldung} ({$positionlat} {$positionlon})";
#-----------------------------------------------------
# und jetzt kommt die lustige Webseite
#-----------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo <<<ENDOFPAGE
<html>
<head>
<link href="stylesichtung.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="stylesichtung_ie.css"></link>
<![endif]-->
<title>Bahnblitze Sichtungen</title>
<meta name="keywords" content="Sichtungen, Sichtungskarte, Live-Map, Eisenbahnfotografie, Deutschland, Live-Karte, Echtzeitkart, Echtzeitdaten, Eisenbahnfotos, Fotos, Modellbahn, Fotostellen, Historische, Eisenbahngeschichte, alle, Überblick, Baureihen, DB-Baureihe, EDV-Nummer, Baureihenüberblick, Leistungsdaten, Baureihe, Bahnfotos, Bahnbilder, Eisenbahnbilder, Eisenbahn, Fotografie, Eisenbahnfotografie, Deutschland, DB AG, Deutsche Bahn AG, DB Schenker, DB Regio, DB Fernverkehr, DB Netz, Bundesbahn " />
<meta name="description" content="Eisenbahnfotos, Webcam, Bahnbilder, Baureihendatenbank. Fotos aus Eisenbahn und Industrie. Bahnfotos aus U-Bahn Berlin, München und Hamburg und Stationen" />
<meta name="google-site-verification" content="AAR8ozhD-3hlIw9jWf5Om0nhWgtG2k6-_qmMGq5LYVY" />
<meta name="google-site-verification" content="AAR8ozhD-3hlIw9jWf5Om0nhWgtG2k6-_qmMGq5LYVY" />
<meta name="google-site-verification" content="syzIMAsM3JGvl5h72-177CShcf_ht3MBe2hmsg5c1iU" />
<meta name="robots" content="index, follow">
<meta name="language" content="de">
<meta name="alexaVerifyID" content="6QfMvVyDKZbX_Fa1twVG7-P7kxA" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
//<![CDATA[
window.onload = function() {
OpenLayers.Lang.setCode('de');
// Position und Zoomstufe der Karte
var mapLon = 6.641389;
var mapLat = 49.756667;
var mapZoom= 7;
// Markerwerte eingestanzt vom PHP
var pinnlat = {$positionlat}; // ******************************
var pinnlon = {$positionlon}; // ******************************
var pinnmeldung = "{$text}"; // ******************************
var map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.PanZoomBar()],
numZoomLevels: 18
});
var layer_mapnik = new OpenLayers.Layer.OSM("Mapnik");
var layer_markers = new OpenLayers.Layer.Markers("Address", {
displayInLayerSwitcher: true
});
map.addLayers([layer_mapnik, layer_markers]);
//jumpTo(lon, lat, zoom);
map.moveTo (new OpenLayers.LonLat(mapLon, mapLat).
transform(map.displayProjection, map.getProjectionObject()), mapZoom);
// addMarker(layer_markers, pinnlon, pinnlat, pinnmeldung);
layer_markers.addMarker(new OpenLayers.Marker(
new OpenLayers.LonLat(pinnlon, pinnlat).
transform(map.displayProjection, map.getProjectionObject())));
};
//]]>
</script>
</head>
<body>
<div id="top">©2015 by bahnblitze.de </div>
<div id="logo">
<div id="menulogo"><img src="icons/logo.png"></div>
<div id="menuintro"><a href="index.php">Home</a></div>
<div id="menuhome"><a href="sichtungen.php">Bahnblitze Sichtungen</a></div>
<div id="menumenu"><a href="#baureihenmenu">Sichtungsmeldungen</a></div>
<div id="menuimpressum"><a href="impressum.php" target="blank">Impressum</a></div>
</div>
<div id="bild"><div id="osm">© <a href="http://www.openstreetmap.org">OpenStreetMap</a>
und <a href="http://www.openstreetmap.org/copyright">Mitwirkende</a>,
<a href="http://creativecommons.org/licenses/by-sa/2.0/deed.de">CC-BY-SA</a>
</div>
<div id="map"></div>
</div>
<div id="inhalt">
<div id="box1">
<b><h2>Herzlich Willkommen auf der Sichtungsseite von Bahnblitze</b></h2>
<br><br>
Auf diesen Seiten finden Sie die aktuellen Sichtungsmeldungen, dargstellt in Listenform und auf einer
Live-karte.
</div>
<div id="box2">
Anbei finden Sie in Kürze einige Angebote von bahnblitze zum Thema Eisenbahnfotografie
</div>
</div></div>
<div id="menu">
<div id="menuallgemein" align="center">
<h2><a name="baureihenmenu">Sichtungsmeldungen<br><br></a></h2></div>
<div id="lp1">
<h2 align="center">Sichtungen aus dem Bahnblitzeforum</h2>
<?php
$ENABLE_CACHING = true; //Before you enable caching set the CACHE_FILE correctly...
$CACHE_FILE = 'bbnews1.rdf'; //Where to store the cache file. HAVE TO BE WRITEABLE FOR THE USER-ACCOUNT OF THE WEBSERVER
$CACHE_REFRESH_TIME = 20; //Cache timeout in minutes
$MAX_NEWS = 10; //If you want to restrict the headlines you can do it here
if ($ENABLE_CACHING){
$cache_diff :(time() - @filemtime($CACHE_FILE))/60;
if (!file_exists($CACHE_FILE) or ($cache_diff > 20) ){
$fcontents = join ('', @file ('http://www.bahnblitze.de/bahnblitzeforum/external.php?action=RSS20'));
@unlink($CACHE_FILE);
$handle = @fopen($CACHE_FILE, 'x+');
@fwrite($handle, $fcontents);
@fclose($handle);
}
$fcontents = join ('', @file ($CACHE_FILE));
} else {
$fcontents = join ('', @file ('http://www.bahnblitze.de/bahnblitzeforum/external.php?action=RSS20'));
}
$fcontents = str_replace ("</item>", "", $fcontents);
$fcontents = str_replace ("</link>", "", $fcontents);
$splices = explode ("<item>", $fcontents);
if (count($splices) > $MAX_NEWS){
$stop_at = $MAX_NEWS+1;
} else {
$stop_at = count($splices);
}
$out_buffer = '<span class="heisenews">';
for ($i = 1; $i < $stop_at; $i++){
$link = explode("<link>",$splices[$i]);
$link[1] = strip_tags($link[1]);
$headline = str_replace ("<title>", '<li><a href="' . trim($link[1]) . '" target="_blank" class="heiseheadline" style="color:#D8D8D8; font-size:1em; text-align: center;">', $splices[$i]);
$headline = str_replace ("</title>", "</a><br></li>", $headline);
$headline = explode ("<link>", $headline);
$headline = $headline[0];
$out_buffer = $out_buffer . $headline . '<img src="1.gif" height="20" width="1" border="0" align="top" alt="" />';
}
$out_buffer = $out_buffer . "</span>";
print $out_buffer;
php?>
</div>
<div id="lp3">
<h2 align="center">Neuste Tourberichte vom Bahnblitze-Team</h2>
<?php
$ENABLE_CACHING = true; //Before you enable caching set the CACHE_FILE correctly...
$CACHE_FILE = 'bbnews.rdf'; //Where to store the cache file. HAVE TO BE WRITEABLE FOR THE USER-ACCOUNT OF THE WEBSERVER
$CACHE_REFRESH_TIME = 20; //Cache timeout in minutes
$MAX_NEWS = 10; //If you want to restrict the headlines you can do it here
if ($ENABLE_CACHING){
$cache_diff :(time() - @filemtime($CACHE_FILE))/60;
if (!file_exists($CACHE_FILE) or ($cache_diff > 20) ){
$fcontents = join ('', @file ('http://bahnblitze.de/test/?feed=rss2'));
@unlink($CACHE_FILE);
$handle = @fopen($CACHE_FILE, 'x+');
@fwrite($handle, $fcontents);
@fclose($handle);
}
$fcontents = join ('', @file ($CACHE_FILE));
} else {
$fcontents = join ('', @file ('http://bahnblitze.de/test/?feed=rss2'));
}
$fcontents = str_replace ("</item>", "", $fcontents);
$fcontents = str_replace ("</link>", "", $fcontents);
$splices = explode ("<item>", $fcontents);
if (count($splices) > $MAX_NEWS){
$stop_at = $MAX_NEWS+1;
} else {
$stop_at = count($splices);
}
$out_buffer = '<span class="heisenews">';
for ($i = 1; $i < $stop_at; $i++){
$link = explode("<link>",$splices[$i]);
$link[1] = strip_tags($link[1]);
$headline = str_replace ("<title>", '<li><a href="' . trim($link[1]) . '" target="_blank" class="heiseheadline" style="color:#D8D8D8; font-size:1em; text-align: center;">', $splices[$i]);
$headline = str_replace ("</title>", "</a><br></li>", $headline);
$headline = explode ("<link>", $headline);
$headline = $headline[0];
$out_buffer = $out_buffer . $headline . '<img src="1.gif" height="20" width="1" border="0" align="top" alt="" />';
}
$out_buffer = $out_buffer . "</span>";
print $out_buffer;
php?>
</div>
</div>
<div id="copyright"></div>
</body>
</html>
ENDOFPAGE;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
?>
Unter anderem habe ich versucht, diesen Abschnitt in eine while-Schleife zu schreiben, und sämtliche Datensätze als Array darzustellen. Interessanterweise komt dabei die Fehlermeldung, dass das Zwischenspeicherlimit überschritten ist,
was aber bei zwei Datensätzen mit jeweils 5 Werten nicht sein kann.
if (mysql_num_rows($result) !=1) { die("Nix oder zuviel gefunden."); }
list ($positionlat, $positionlon, $meldung) = mysql_fetch_row($result);
wurde ersetzt gegen:
while($row = mysql_fetch_array($result)) {
list ($positionlat, $positionlon, $meldung) = $row;
}