Jump to content

Recommended Posts

I seem to have a problem.  I am making a store locator and my php does not seem to been getting the data from the db.  Here is a link to the page http://www.evolvegolf.com/phpsqlsearch_genxml.php

 

and here is the php code associated with it:

 

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

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','<',$htmlStr); 
$xmlStr=str_replace('>','>',$xmlStr); 
$xmlStr=str_replace('"','"',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$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 (localhost, 'evolvego_evlglf', 'XXXX');
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db('evolvego_stores', $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, ( 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());
}

// 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";

?>

 

I really hope someone can help me because I am LOST.

Link to comment
https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/
Share on other sites

does not seem to been getting the data from the db

 

Yes, but what is it doing? What do you see in front of you that would give us a clue where to look for the problem? A blank page? mysql_error() output? XML output that has empty values where the data is? No XML output at all? What does a "view source" in your browser of the page show?

 

And please get rid of the @ in front of the @mysql_fetch_assoc(). That just hides errors that would help you troubleshoot (and that instruction won't produce an error if your query executes without an error of its' own.) A query that executes but matches zero rows does NOT cause any of the mysql_fetch_xxxx statements to output an error.

This is what I get on the screen (there was a link in the first post):

 

This XML file does not appear to have any style information associated with it. The document tree is shown below.

     

<markers>

</markers>

 

 

This is the error that I get:

 

Error: Permission denied for <http://talkgadget.google.com> to call method Location.toString on <http://www.google.com>.

 

and

 

Error: unterminated string literal

Source File: http://www.google.com/

Line: 99

 

I am sorry if I am asking basic questions, but I have never worked with mysql before and the instructions provided by google seemed straight forward enough...

 

this

Error: Permission denied for <http://talkgadget.google.com> to call method Location.toString on <http://www.google.com>.

is a javascript error I believe, and one that I commonly see in my error console when visiting sites. besides that error comes from google, as well as the other error. So I don't think either of those have anything to do with your PHP.

 

Do you get any PHP errors? Don't check your javascript error console for PHP errors

You are going to find that most people are not going to click on unknown links in posts, nor download files, so it is always best to post the relevant information.

 

You have marked this thread as "Solved". Is that correct? Edit: And now you have marked it as not solved...  :o

 

The output indicates that the query returned no rows. Either the WHERE clause did not match anything or there is nothing in the table to match. As Mark Baker stated in his reply, you need to check if a query returned any matching rows and take appropriate action, such as outputting a "No matching data found" message when it does not so that you give feedback to the visitor as to what actually happened.

It is not solved, I did not mean to hit the solved button.

 

It would seem that it did not return anything because there is no information between <marker></marker> and I know that there is information in the db.

 

I am just SO confused...

 

 

 

 

 

It is not solved, I did not mean to hit the solved button. It would seem that it did not return anything because there is no information between <marker></marker>.

<?php header("Content-type: text/xml"); function parseToXML($htmlStr) { $xmlStr=str_replace('<','<',$htmlStr); $xmlStr=str_replace('>','>',$xmlStr); $xmlStr=str_replace('"','"',$xmlStr); $xmlStr=str_replace("'",''',$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 (localhost, 'evolvego_evlglf', 'where2buy'); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db('evolvego_stores', $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, ( 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()); } // 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"; ?> 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.