Found this script by smooth designers but it has a error I cant work out? http://www.smoothdesigners.com/2008/05/creating-a-simple-full-screen-visitor-map-with-google-maps/ Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/domainname/map/visitormap.php on line 14 Code is require 'config.php'; mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $ip = $_SERVER['REMOTE_ADDR']; $userinfo = IPtoCoords($ip); $user = mysql_query('SELECT `location` FROM `visitor_map` WHERE `location` = \'' . $userinfo['location'] . '\''); $totalusers = mysql_query('SELECT count(id) from visitor_map'); $totalHits = mysql_query('SELECT sum(hits) from visitor_map'); $total = mysql_fetch_array($totalusers); $thits = mysql_fetch_array($totalHits); if(!mysql_fetch_row($user) && $userinfo) mysql_query('INSERT INTO `visitor_map` (`location`, `longitude`, `latitude`) VALUES (\'' . $userinfo['location'] . '\', ' . $userinfo['longitude'] . ', ' . $userinfo['latitude'] . ')') or die(mysql_error());
It's because it's bad coding. The fact that the sample on their web site doesn't work should tell you something. The table their code creates neglects to create a column called 'hits', so of course querying it with the code will produce an error...
Is this line working? 'SELECT `location` FROM `visitor_map` WHERE `location` = \'' . $userinfo['location'] . '\'' Code (markup): Try replacing it with this: "SELECT `location` FROM `visitor_map` WHERE `location` = '".$userinfo['location']."'" Code (markup): As for the totalHits query - does the field "hits" exist and is it an integer?
Danltn can you explain better your suggestion? Yesideez changed to below is this correct? $user = mysql_query("SELECT `location` FROM `visitor_map` WHERE `location` = '".$userinfo['location']."'" As for the totalHits query - does the field "hits" exist and is it an integer? Sorry I dont know? caribbean_hatch So I need to add column called 'hits' ??? Does any one know how to point me in the right direction? Ps thanks for all the replies
$user = mysql_query("SELECT `location` FROM `visitor_map` WHERE `location` = '".$userinfo['location']."'"); PHP:
Yesideez $user = mysql_query("SELECT `location` FROM `visitor_map` WHERE `location` = '".$userinfo['location']."'"); Ok cant see any errors I need to add column called 'hits' ??? Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.domainname.com/web-site-design/map/visitormap.php on line 15
Be warned that when PHP returns a line number for an error the actual cause of the error may actually be earlier in the script. caribbean_hatch is right - there's no "hits" field - I've no idea what it should be.
true I understand that and yes I need to work out the hits column trying -- -- Table structure for table `visitor_map` -- CREATE TABLE IF NOT EXISTS `visitor_map` ( `id` int(11) NOT NULL auto_increment, `hits` int(11) NOT NULL, `location` varchar(32) NOT NULL, `longitude` float NOT NULL, `latitude` float NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `visitor_map` --
the other thing I do not understand is this function part in bold I have a google map and yahoo map api but..... whats XX is that the starting location? function IPtoCoords($ip) { $dom = new DOMDocument(); $ipcheck = ip2long($ip); if($ipcheck == -1 || $ipcheck === false) trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); else $uri = 'http://api.hostip.info/?ip=' . $ip; $dom->load($uri); $location = (strpos($dom->getElementsByTagName('name')->item(1)->nodeValue, 'Unknown') === false) ? $dom->getElementsByTagName('name')->item(1)->nodeValue : $dom->getElementsByTagName('countryAbbrev')->item(0)->nodeValue; if($location == 'XX') return false; else { $dom->load('http://local.yahooapis.com/MapsService/V1/geocode?appid=' . Yahoo_Key . '&location=' . $location); $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); } } ?>
Just had another look at the opriginal scripts - these two lines can be removed (add // at the start to disable them) //$totalHits = mysql_query('SELECT sum(hits) from visitor_map'); PHP: //$thits = mysql_fetch_array($totalHits); PHP: That's the only places those two variables (totalhits and thits are being used!) Now try the scripts and see if you get any errors.
No errors appear so you think its a extra table? Added a include on to a page that is getting hits called it tracker.php require_once('map/tracker.php'); <?php require 'config.php'; mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $ip = $_SERVER['REMOTE_ADDR']; $userinfo = IPtoCoords($ip); $user = mysql_query('SELECT `location` FROM `visitor_map` WHERE `location` = \'' . $userinfo['location'] . '\''); if(!mysql_fetch_row($user) && $userinfo) mysql_query('INSERT INTO `visitor_map` (`location`, `longitude`, `latitude`) VALUES (\'' . $userinfo['location'] . '\', ' . $userinfo['longitude'] . ', ' . $userinfo['latitude'] . ')') or die(mysql_error()); ?> this should enter hits/locations etc into the DB right and then from visitormap.php I should now see some pointers?
It's not an extra table - might be worth contacting the authors and let them know hits is missing from the table. As for the last piece of code you posted - hits isn't being accessed in there either.
yes I have posted to the author to see what they say. Thanks for your help I will carry on trying to see why it doesnt log any pointers to the map
see to be a very similar script with issues as well http://www.zymic.com/tutorials/php/create-a-visitor-map/
how do you find out if your host allows a script to open a remote file or url? failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request trying to run this basic function? <?php function IPtoCoords($ip) { $dom = new DOMDocument(); $ipcheck = ip2long($ip); if($ipcheck == -1 || $ipcheck === false) trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); else $uri = 'http://api.hostip.info/?ip=' . $ip; $dom->load($uri); $location = (strpos($dom->getElementsByTagName('name')->item(1)->nodeValue, 'Unknown') === false) ? $dom->getElementsByTagName('name')->item(1)->nodeValue : $dom->getElementsByTagName('countryAbbrev')->item(0)->nodeValue; if($location == 'XX') return false; else { $dom->load('http://local.yahooapis.com/MapsService/V1/geocode?appid=YahooDemo&location=' . $location); $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); } } //$ip = $_SERVER['REMOTE_ADDR']; $ip = '65.55.232.11'; $userinfo = IPtoCoords($ip); echo $ip; echo "<br /><br />"; echo $userinfo; echo "<br /><br />"; echo $ipcheck; ?>
<? /* Your Google Maps API key */ define('API_KEY', 'mygooglekey'); /* Your Yahoo Application Key */ define('Yahoo_Key', 'myYahookey'); //$ip = $_SERVER['REMOTE_ADDR']; $ip = '65.55.232.11'; //$userinfo = IPtoCoords($ip); //function IPtoCoords($ip) //{ $dom = new DOMDocument(); $ipcheck = ip2long($ip); if($ipcheck == -1 || $ipcheck === false) trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); else $uri = 'http://api.hostip.info/?ip=' . $ip; $dom->load($uri); $location = (strpos($dom->getElementsByTagName('name')->item(1)->nodeValue, 'Unknown') === false) ? $dom->getElementsByTagName('name')->item(1)->nodeValue : $dom->getElementsByTagName('countryAbbrev')->item(0)->nodeValue; if($location == 'XX') return false; else { $dom->load('http://local.yahooapis.com/MapsService/V1/geocode?appid=' . Yahoo_Key . '&location=' . $location); $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; //return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); //return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); } //} echo $ipcheck; echo "<br /><br />"; echo $uri; echo "<br /><br />"; //echo $dom; echo "<br /><br />"; echo $longitude; echo "<br /><br />"; echo $latitude; echo "<br /><br />"; echo $location; echo "<br /><br />"; echo Yahoo_Key; echo "<br /><br />"; echo $dom; ?> trying to check this function works but I get Catchable fatal error: Object of class DOMDocument could not be converted to string in /home/domainame.com/visitors-map/visitormap.php on line 58 Line in bold seems to be my issue? Output from the echos is 1094182923 http://api.hostip.info/?ip=65.55.232.11 -98.58 39.83 US vGj0q5fV34FdXkvfhBw62tmyYahooKey-MKCAuj3G30s0iNqlBorNoZ.tLSM If I input a line http://local.yahooapis.com/MapsServ...w62tmyYahooKey-MKCAuj3G30s0iNqlBorNoZ.tLSM=US Catchable fatal error: Object of class DOMDocument could not be converted to string in /domain.com/visitors-map/test100.php on line 57 result from Yahoo is <ResultSet xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"> − <Result precision="country"> <Latitude>39.83</Latitude> <Longitude>-98.58</Longitude> <Address/> <City/> <State/> <Zip/> <Country>US</Country> </Result> </ResultSet> − <!-- ws02.search.scd.yahoo.com compressed/chunked Sun Dec 21 01:04:59 PST 2008 -->
SWAPSHOP.. Hey, could you put [ php] [ /php] around your code to make it more readable to us trying to help. Thanks.