Output XML con PHP risultato vuoto

Gioweb

Nuovo Utente
2 Apr 2014
21
0
0
Buongiorno sto facendo qualche prova con la guida "Creating a Store Locator with PHP, MySQL & Google Maps" a questo indirizzo: https://developers.google.com/maps/articles/phpsqlsearch_v3 la guida originaria è del 2009 ma c'è un aggiornamento recentissimo il 24 aprile 2014

Ho creato la tabella popolato il database, impostato il file di connessione e caricato tutto sul server per vedere se riesco a creare il file xml, questo è il codice:

PHP:
<?php
require("phpsqlsearch_dbinfo.php");

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);


// Opens a connection to a mySQL server
$connection=mysql_connect ('mysql.SERVERXXXXXXXX.it', $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}

// Search the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));
$result = mysql_query($query);

$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $row['name']);
  $newnode->setAttribute("address", $row['address']);
  $newnode->setAttribute("lat", $row['lat']);
  $newnode->setAttribute("lng", $row['lng']);
  $newnode->setAttribute("distance", $row['distance']);
}

echo $dom->saveXML();
?>


il risultato però non restituisce dati, neanche errori di connessione ma solo un malinconico:

<?xml version="1.0"?>
<markers/>

Dati nel db ci sono, ho l'impressione che ci sia qualche cosa che mi sfugge o che non capisco in questa parte di codice:

PHP:
// Search the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",


Ringrazio in anticipo!
 
Ultima modifica:

Gioweb

Nuovo Utente
2 Apr 2014
21
0
0
Specifico che la versione di PHP è la 5 in quanto nella guida dice che il codice su non va bene per la versione 4 e suggerisce questo

PHP:
<?php
header("Content-type: text/xml");
require("phpsqlsearch_dbinfo.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace('“','&quot;',$xmlStr); 
$xmlStr=str_replace('”','&quot;',$xmlStr); 
$xmlStr=str_replace("'",''',$xmlStr); 

return $xmlStr; 
} 

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];

// Opens a connection to a MySQL server
$connection=mysql_connect ("mysql.XXXXXXXXX.it", $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = sprintf("SELECT address, name, lat, lng, ( 6371 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));

$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

// Start XML file, echo parent node
echo "<markers>\n";
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'distance="' . $row['distance'] . '" ';
  echo "/>\n";
}

// End XML file
echo "</markers>\n";

?>

ma anche impostando la versione 4 e usando questo codice il risultato è:

<markers></markers>

cosa posso provare a fare? Grazie!
 

Gioweb

Nuovo Utente
2 Apr 2014
21
0
0
la notte porta consiglio, adesso funziona...

PHP:
header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<?xml version="1.0"?>\n';
echo '<markers>\n';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'distance="' . $row['distance'] . '" ';
  echo '/>\n';
}

// End XML file
echo '</markers>\n';

?>

grazie comunque!
 
Discussioni simili
Autore Titolo Forum Risposte Data
D Lettura output da json su php PHP 4
B App che riconosce output schermo Sviluppo app per iOS 1
A [PHP] FPDF error: Some data has already been output, can't send PDF file PHP 5
romeocharly input/output errror code 451 Discussioni Varie 0
P [SOLVED] salvare il TCPDF output in mysql e rivisualizzarlo PHP 3
P [Javascript] [html5] operazioni matematiche come output di un form Javascript 7
I [PHP] shell_exec output in un array PHP 14
F Output html function jQuery 1
J Mysql tabella output in JSON PHP 2
filippino Impostazioni di output (PDF) in photoshop per la stampa Photoshop 1
M Generazione output Java 2
S [risolto] cache dell'html di output PHP 2
Emix Formattazione output txt dopo lettura contenuti PHP 31
E getimagesize() non da nessun output PHP 2
A Aggiungere tag nel DOM a parola/e selezionata/e nel output Javascript 15
S GD e output in pagina PHP 11
Sevenjeak [C / Eclipse] errore nell'output della console Programmazione 0
ivarello Inserire <output> nel Value dell'Input HTML e CSS 0
V problema con form in input/output PHP 3
C Un form di input e uno di output con funzione javascript Javascript 17
S Output file php in formato testo PHP 9
S Shell Output sul browser in tempo reale PHP 2
M W3C Invalid Output HTML e CSS 9
G output radio button PHP 2
A Problemi di output Classic ASP 5
M Ridirezionamento Output Php PHP 1
M Warning: Cannot modify header information - headers already sent by (output started a PHP 1
F [help] produrre file output php-mysql PHP 1
V php e l'Output buffering PHP 1
S Form, problemi di output Classic ASP 0
D Miglior modo per estrarre le occorrenze di un elemento in un set di più file xml e quindi scrivere il risultato in una tabella Excel o magari in JSON XML 0
B Da XML a TXT x4 XML 0
B ciclare file xml con PHP PHP 1
P Rimozione automatica url da sitemap.xml con PHP PHP 1
P Modifica con PHP di un node in una sitemap xml PHP 0
M modificare un file .XML da database Sql PHP 13
T Da xsd a xml ed inserimento dati in excel XML 0
C Problema con dati meteo xml XML 1
R Cerco esperto XML Offerte e Richieste di Lavoro e/o Collaborazione 0
E [PHP] creare temporary table per dati da xml PHP 2
G XML raccolta brani XML 1
P [CERCO] Webmaster per cataloghi prodotti csv/xml Offerte e Richieste di Lavoro e/o Collaborazione 3
S aggiornare valore di un elemento xml con php PHP 8
G Errore Cannot read property 'childNodes' of undefined per mancanza nodo nel file xml XML 6
A [PHP] Prelievo dati da xml online. PHP 9
L XML zip XML 3
Simone P Fatturazione elettronica xml e invio SDI Discussioni Varie 53
L [PHP] parsing xml PHP 1
J XML e css XML 0
P Importazione dati da file xml in db mysql con php PHP 17

Discussioni simili