当我发现时,我正在关注this教程,我无法查看预期的输出,因为我无法以xml格式查看我的数据。我稍微更改了配置数据,不知道是不是故障原因?
<?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 (localhost, 'root', '12345678');
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db('demo', $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);
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();
?>
我希望得到类似的结果http://gmaps-samples.googlecode.com/svn/trunk/articles-phpsqlsearch/phpsqlsearch_expectedoutput.xml,但似乎没有任何结果。好像它没有任何数据,但我已经在我的mysql中导入了数据。
答案 0 :(得分:1)
问题的第一步:
<?php
// Get parameters from URL
$center_lat = ( isset( $_GET["lat"] ) ? $_GET["lat"] : 0 ); # You could replace these "0"s with the
$center_lng = ( isset( $_GET["lng"] ) ? $_GET["lng"] : 0 ); # Lat/Lng of a default location.
$radius = ( isset( $_GET["radius"] ) ? $_GET["radius"] : 10 ); # Again, default 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
if( !( $connection = mysql_connect( 'localhost' , 'root' , '12345678' ) ) ) # The SQL Server address must be a string or IP address
die( "MySQL Error - Failed to connect to Server : " . mysql_error() );
// Set the active mySQL database
if( !mysql_select_db( 'demo' , $connection ) );
die( "MySQL Error - Failed to connect to Database : " . 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 );
if( !$result )
die( "MySQL Error - Invalid query: " . mysql_error() . ' "'.$query.'"' ); # During debugging, echo the SQL Statement on Error
if( !headers_sent() )
header( "Content-type: text/xml" );
// Iterate through the rows, adding XML nodes for each
if( mysql_num_rows( $result ) ){
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']);
}
}else
die( 'MySQL Error - No Records Returned "'.$query.'"' );
echo $dom->saveXML();
?>
给它一个去,让我们知道你看到的任何进一步的错误信息。
答案 1 :(得分:0)
我有同样的问题,没有数据,这里是错误
MySQL错误 - 没有记录返回“SELECT地址,名称,lat,lng,(3959 * acos(cos(弧度('37'))* cos(弧度(lat))* cos(弧度(lng) - 弧度('-122'))+ sin(弧度('37'))* sin(弧度(纬度))))AS距离距离标记距离&lt; '25'ORDER BY距离LIMIT 0,20“
数据库已填充,我发送get vars,如下所示: http://localhost/superga/lib/phpsqlsearch_genxml.php?lat=37&lng=-122&radius=25
感谢
答案 2 :(得分:0)
我正在遵循相同的教程,并在同一点上在道路上弯曲。 我已经按照上面的所有建议,仍然没有决心。 我的错误是;
此页面包含以下错误: 第1行第1行的错误:文档为空 下面是第一个错误的页面呈现。
任何人都可以上班吗?
保