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

  • Home
  • SEARCH
  • 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 8943479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:46:51+00:00 2026-06-15T11:46:51+00:00

I have a php code which gets location information from database (test) and table

  • 0

I have a php code which gets location information from database (test) and table name manu which is created using the phpmyadmin in wamp and display those locations on map using markers. Location details in the sense latitude and longitude value.

UPDATED

<?
$dbname            ='test'; //Name of the database
$dbuser            =''; //Username for the db
$dbpass            =''; //Password for the db
$dbserver          ='localhost'; //Name of the mysql server

$dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
mysql_select_db("$dbname") or die(mysql_error());
 ?>


 <html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
 <style type="text/css">
  body { font: normal 10pt Helvetica, Arial; }
 #map { width: 350px; height: 300px; border: 0px; padding: 0px; }
 </style>
 <script src="http://maps.google.com/maps/api/js?v=3&sensor=false"        type="text/javascript" ></script>
 <script type="text/javascript" src="js/jquery.js"></script>
 <script type="text/javascript">

  var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
  new google.maps.Size(32, 32), new google.maps.Point(0, 0),
  new google.maps.Point(16, 32));
  var center = null;
  var map = null;
  var currentPopup;
  var bounds = new google.maps.LatLngBounds();
  function addMarker(lat, lng, info) {
  var pt = new google.maps.LatLng(lat, lng);
  bounds.extend(pt);
  var marker = new google.maps.Marker({
  position: pt,
  icon: icon,
  map: map
  });
  var popup = new google.maps.InfoWindow({
  content: info,
  maxWidth: 300
  });

   google.maps.event.addListener(marker, "click", function() {
 if (currentPopup != null) {
   currentPopup.close();
  currentPopup = null;
  }
   popup.open(map, marker);
  currentPopup = popup;
 });
 google.maps.event.addListener(popup, "closeclick", function() {
 map.panTo(center);
  currentPopup = null;
 });
 }
 function initMap() {
 map = new google.maps.Map(document.getElementById("map"), {
 center: new google.maps.LatLng(0, 0),
  zoom: 14,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  mapTypeControl: false,
  mapTypeControlOptions: {
  style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
  },
  navigationControl: true,
  navigationControlOptions: {
  style: google.maps.NavigationControlStyle.SMALL
  }
   });


 $.getJSON('googlescript.php', function(items)
 {
 for (var i = 0; i < items.length; i++) 
 {
 (function(item) 
 {
 addMarker(item.lat, item.long, item.name + ' ' + item.desc);
 })(items[i]);
 }

 });


 center = bounds.getCenter();
  map.fitBounds(bounds);
 }

  </script>
  </head>
  <body onload="initMap()" style="margin:0px; border:0px; padding:0px;">
   <div id="map"></div>
  </body>
   </html>

googlescript.php file code :

   <?php

   $dbname            ='test'; //Name of the database
   $dbuser            =''; //Username for the db
   $dbpass            =''; //Password for the db
   $dbserver          ='localhost'; //Name of the mysql server
   $tbl_name          ='manu';

   $dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
   mysql_select_db("$dbname") or die(mysql_error());

   $query = mysql_query("SELECT * FROM manu")or die(mysql_error());

   header('Content-Type: application/json');

   $rows = array();
   while ($row = mysql_fetch_array($query))
   {
    $rows[] = $row;
   }
  echo json_encode($rows);
  exit;
   ?>
  • 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-06-15T11:46:52+00:00Added an answer on June 15, 2026 at 11:46 am

    Html Page

    body onload="initMap()" //you forget to close it.
    div id="map"

    Made below change in html file.

    script src="http://maps.google.com/maps/api/js?v=3&sensor=false"    type="text/javascript"
    script type="text/javascript" src="js/jquery.js"
    script type="text/javascript">
        var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
        new google.maps.Size(32, 32), new google.maps.Point(0, 0),
        new google.maps.Point(16, 32));
        var center = null;
        var map = null;
        var currentPopup;
        var bounds = new google.maps.LatLngBounds();
        function addMarker(lat, lng, info)
        {
            var pt = new google.maps.LatLng(lat, lng);
            bounds.extend(pt);
            var marker = new google.maps.Marker(
            {
                position: pt,
                icon: icon,
                map: map
            });
            var popup = new google.maps.InfoWindow(
            {
                content: info,
                maxWidth: 300
            });

        google.maps.event.addListener(marker, "click", function()
        {
            if (currentPopup != null)
            {
                currentPopup.close();
                currentPopup = null;
            }
            popup.open(map, marker);
            currentPopup = popup;
        });
        google.maps.event.addListener(popup, "closeclick", function()
        {
            map.panTo(center);
            currentPopup = null;
        });
    }
    

    function initMap()
    {
    map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(0, 0),
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false,
    mapTypeControlOptions:
    {
    style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
    },
    navigationControl: true,
    navigationControlOptions:
    {
    style: google.maps.NavigationControlStyle.SMALL
    }
    });

    // getjson code goes here which is as below because i was unable to format it here so i wrote it downward.
    
    center = bounds.getCenter();
    map.fitBounds(bounds);
    

    }
    /script>


    $.getJSON('googlescript.php', function(items)
    {
    for (var i = 0; i < items.length; i++)
    {
    (function(item)
    {
    addMarker(item.lat, item.long, item.name + ' ' + item.desc);
    })(items[i]);
    }

    });

    I have used $.getJSON('googlescript.php', so you need to create a googlescript.php file and paste below code in it.

    $query = mysql_query("SELECT * FROM manu")or die(mysql_error());
    
    header('Content-Type: application/json');
    
    $rows = array();
    while ($row = mysql_fetch_array($query))
    {
        $rows[] = $row;
    }
    echo json_encode($rows);
    exit;
    

    ?>

    Now check it in action and I’m sure you will get result that you wanted.
    Do not forget to change jquery path and change database connection setting and please place jquery path proper.

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

Sidebar

Related Questions

I have written PHP code which connects to MYSQL to look up information, sends
I have the following PHP code which works out the possible combinations from a
I have this code which will include template.php file from inside each of these
I have a php script which... Deletes a record from a MySql table (based
If I have a page which gets generated using PHP and then modified using
I basically have an ajax function which gets the latest posts from a database,
I have PHP code which connects to MySql and encodes data to JSON. Later
I have some PHP code which allows me to sort a column into ascending
I have some PHP code which stores whatever is typed in a textbox in
I have the following php code which I want to add a delay too:

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.