knotbuilder Posted September 11, 2009 Share Posted September 11, 2009 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("'",''',$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. Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/ Share on other sites More sharing options...
mikesta707 Posted September 11, 2009 Share Posted September 11, 2009 Try removing the @ from infront of your mysql_fetch_assoc. That may be suppressing a warning or error that would help you in the debugging Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-916800 Share on other sites More sharing options...
Mark Baker Posted September 11, 2009 Share Posted September 11, 2009 You could also try a check of mysql_num_rows before your while loop, to confirm that no rows have been returned. And try echoing out $query and running it through phpmyadmin as well Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-916804 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2009 Share Posted September 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-916805 Share on other sites More sharing options...
knotbuilder Posted September 11, 2009 Author Share Posted September 11, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-916814 Share on other sites More sharing options...
mikesta707 Posted September 11, 2009 Share Posted September 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-916819 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2009 Share Posted September 11, 2009 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... 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. Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-916824 Share on other sites More sharing options...
knotbuilder Posted September 11, 2009 Author Share Posted September 11, 2009 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-916835 Share on other sites More sharing options...
knotbuilder Posted September 14, 2009 Author Share Posted September 14, 2009 Do you get any PHP errors? Don't check your javascript error console for PHP errors No I don't get any PHP errors (that I see anyway)... Quote Link to comment https://forums.phpfreaks.com/topic/173919-php-will-not-display-db-values/#findComment-918388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.