Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6253953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:06:45+00:00 2026-05-24T14:06:45+00:00

I wonder whether someone may be able to help me please. I am using

  • 0

I wonder whether someone may be able to help me please.

I am using the code below to correctly show markers for all the locations stored in mySQL database.

PHP

<?php 
require("phpfile.php"); 

// 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 ("hostname", $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 

Amended Code

$query = "select l.locationname, l.address, l.osgb36lat, l.osgb36lon, count(*) as totalfinds from locations as l left join finds as f on l.locationid=f.locationid"; 
        $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)){ 
    // ADD TO XML DOCUMENT NODE 
    $node = $dom->createElement("marker"); 
    $newnode = $parnode->appendChild($node); 
    $newnode->setAttribute("locationname",$row['locationname']); 
    $newnode->setAttribute("address",$row['address']); 
    $newnode->setAttribute("osgb36lat",$row['osgb36lat']); 
    $newnode->setAttribute("osgb36lon",$row['osgb36lon']); 
    $newnode->setAttribute("finds",$row['finds']);
    $newnode->setAttribute("totalfinds",$row['totalfinds']);
    }  
        } 

        echo $dom->saveXML(); 

        ?>

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Locations</title>
        <link rel="stylesheet" href="css/alllocationsstyle.css" type="text/css" media="all" />
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
        <script type="text/javascript"> 
            var customIcons = {
            0: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
            },
            1: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_green.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
            }
            };

            function load() { 
            var map = new google.maps.Map(document.getElementById("map"), { 
            center: new google.maps.LatLng(54.312195845815246,-4.45948481875007), 
            zoom:6, 
            mapTypeId: 'roadmap' 
            }); 

            var infoWindow = new google.maps.InfoWindow;

            // Change this depending on the name of your PHP file 
            downloadUrl("phpfile.php", function(data) { 
            var xml = data.responseXML; 
            var markers = xml.documentElement.getElementsByTagName("marker"); 
            for (var i = 0; i < markers.length; i++) { 
            var locationname = markers[i].getAttribute("locationname"); 
            var address = markers[i].getAttribute("address");
            var finds = markers[i].getAttribute("finds");
            var totalfinds = markers[i].getAttribute("totalfinds");
            var point = new google.maps.LatLng( 
            parseFloat(markers[i].getAttribute("osgb36lat")), 
            parseFloat(markers[i].getAttribute("osgb36lon")));
            var html = "<b>" + locationname + "</b>";
            var icon = customIcons[finds] || {};
            var marker = new google.maps.Marker({          
            map: map, 
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
            }); 
            bindInfoWindow(marker, map, infoWindow, html);
            } 
            }); 
            } 
            function bindInfoWindow(marker, map, infoWindow, html) {
            google.maps.event.addListener(marker, 'click', function() {
            infoWindow.setContent(html);
            infoWindow.open(map, marker);
            });
            }

            function downloadUrl(url, callback) { 
            var request = window.ActiveXObject ? 
            new ActiveXObject('Microsoft.XMLHTTP') : 
            new XMLHttpRequest; 

            request.onreadystatechange = function() { 
            if (request.readyState == 4) { 
            request.onreadystatechange = doNothing; 
            callback(request, request.status); 
            } 
            }; 

            request.open('GET', url, true); 
            request.send(null); 
            } 

            function doNothing() {} 

            </script> 
            </head> 

            <body onLoad="load()">
                <div id="map"></div>
            </body> 
            </html>

What I would like to do is to adapt the coding whereby the ‘Total number of finds’ for each location is shown along with the ‘Location Name’ in the Infowindow that is created for each marker.

I know that I need to get this information from my table called ‘finds’ where I need to count the number of rows where the ‘locationid’ matches the one in the ‘locations’ table, but I must admit I haven’t a clue how to do this.

I just wondered whether someone could perhaps please provide some guidance on what I need to do to achieve this.

Many thanks and kind regards

Chris

Finds SQL Dump

-- 
-- Table structure for table `finds`
-- 
DROP TABLE IF EXISTS `finds`;
CREATE TABLE IF NOT EXISTS `finds` (
  `userid` int(6) NOT NULL,
  `locationid` int(6) NOT NULL,
  `findid` int(6) NOT NULL auto_increment,
  `findosgb36lat` float(10,6) NOT NULL,
  `findosgb36lon` float(10,6) NOT NULL,
  `dateoftrip` varchar(8) NOT NULL,
  `findname` varchar(35) NOT NULL,
  `finddescription` varchar(100) NOT NULL,
  `findimage` varchar(200) default NULL,
  `additionalcomments` varchar(600) default NULL,
  `makepublic` varchar(3) NOT NULL default 'no',
  PRIMARY KEY  (`findid`)
) ENGINE=MyISAM AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 AUTO_INCREMENT=34 ;

Locations SQL dump

-- 
-- Table structure for table `locations`
-- 

CREATE TABLE `locations` (
  `userid` int(6) NOT NULL,
  `locationid` int(6) NOT NULL auto_increment,
  `locationname` varchar(80) NOT NULL,
  `address` varchar(110) NOT NULL,
  `osgb36lat` float(10,6) NOT NULL,
  `osgb36lon` float(10,6) NOT NULL,
  `osgridref` varchar(20) NOT NULL,
  `wgs84latd` int(2) NOT NULL,
  `wgs84latm` int(2) NOT NULL,
  `wgs84lats` decimal(6,2) NOT NULL,
  `wgs84latb` varchar(1) NOT NULL,
  `wgs84lond` int(2) NOT NULL,
  `wgs84lonm` int(2) NOT NULL,
  `wgs84lons` decimal(6,2) NOT NULL,
  `wgs84lonb` varchar(1) NOT NULL,
  `nameoflocationcontact` varchar(30) NOT NULL,
  `locationcontactsaddressline1` varchar(50) NOT NULL,
  `locationcontactsaddressline2` varchar(50) default NULL,
  `locationcontactsaddressline3` varchar(50) default NULL,
  `locationcontactsaddressline4` varchar(50) default NULL,
  `locationcontactstelephonenumber` varchar(15) default NULL,
  `finds` int(1) NOT NULL,
  PRIMARY KEY  (`locationid`)
) ENGINE=MyISAM AUTO_INCREMENT=27 DEFAULT CHARSET=utf8 AUTO_INCREMENT=27 ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:06:45+00:00Added an answer on May 24, 2026 at 2:06 pm

    You’d want to change the sql fetching code to join the finds table. Left join seems suitable for this.

    Updated sql code:

    select l.locationid, f.locationid, l.locationname, l.address,
    l.osgb36lat, l.osgb36lon, l.finds, count(f.locationid) as totalfinds
    from locations as l left join finds as f on l.locationid=f.locationid
    group by l.locationid

    You will now be able to get the total number of location finds in the total_finds element of the $row array. Also note I removed the where 1 condition in the original sql as it makes no sense.

    Of course you’ll also need save the total_finds value in the XML and make the appropriate changes in the JS code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder whether someone may be able to help me please. I'm using the
I wonder whether someone may be able to help me please. I'm using the
I wonder whether someone may be able to help me please with a error
I wonder whether someone may be able to help me please. I'm trying to
I wonder whether someone may be able to help me please. I've put some
I wonder whether someone may be able to help me please. I'm wanting to
I wonder whether someone may be able to help me please. I'm currently working
I wonder whether someone may be able to help me please. I've been working
I wonder whether someone may be able to help me please. I've put together
I wonder whether someone may be able to help me please. I've put together

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.