Guest User

HD's stuff

a guest
Dec 29th, 2011
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.27 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5.     <head>
  6.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  7.         <title>Frum London Directory Map</title>
  8.         <link rel="stylesheet" type="text/css" href="style.css" />
  9.         <link rel="stylesheet" type="text/css" href="menu/menu_style.css" />
  10.  
  11.         <!--[if IE]>
  12.         <link rel="stylesheet" type="text/css" href="menu/ie.css" />
  13.         <![endif]-->
  14.  
  15.         <style type="text/css">#map_canvas {
  16.             width:  100%;
  17.             height: 400px;
  18.         }</style>
  19.     </head>
  20.  
  21.     <body bgcolor="#006" onload="initialize()">
  22.         <!-- Title Logo -->
  23.  
  24.         <div align="center">
  25.             <img src="logo.png" width="984" height="76" />
  26.         </div>
  27.  
  28.         <div class="nav">
  29.             <div class="table">
  30.                 <ul class="select">
  31.                     <li><a href="" target="_self"><b>Kosher</b></a>
  32.                         <div class="select_sub">
  33.                             <ul class="sub">
  34.                                 <li><a href="" target="_self">Bakeries</a></li>
  35.                                 <li><a href="" target="_self">Cafes</a></li>
  36.                                 <li><a href="" target="_self">Restaurants</a></li>
  37.                                 <li><a href="" target="_self">Groceries</a></li>
  38.                                 <li><a href="" target="_self">Confectionary</a></li>
  39.                             </ul>
  40.                         </div>
  41.                     </li>
  42.                 </ul>
  43.  
  44.                 <ul class="select">
  45.                     <li><a href="" target="_self"><b>Religious</b></a>
  46.                         <div class="select_sub">
  47.                             <ul class="sub">
  48.                                 <li><a href="" target="_self">Shuls & Synagogues</a></li>
  49.                                 <li><a href="" target="_self">Tefillos</a></li>
  50.                                 <li><a href="" target="_self">Mincha</a></li>
  51.                             </ul>
  52.                         </div>
  53.                     </li>
  54.                 </ul>
  55.  
  56.                 <ul class="select">
  57.                     <li><a href="" target="_self"><b>Travel</b></a>
  58.                         <div class="select_sub">
  59.                             <ul class="sub">
  60.                                 <li><a href="" target="_self">Hotels</a></li>
  61.                                 <li><a href="" target="_self">Inns</a></li>
  62.                                 <li><a href="" target="_self">Tours</a></li>
  63.                                 <li><a href="" target="_self">Flights</a></li>
  64.                                 <li><a href="" target="_self">Taxis</a></li>
  65.                             </ul>
  66.                         </div>
  67.                     </li>
  68.                 </ul>
  69.  
  70.                 <ul class="select">
  71.                     <li><a href="" target="_self"><b>Business</b></a>
  72.                         <div class="select_sub">
  73.                             <ul class="sub">
  74.                                 <li><a href="" target="_self">Financial Services</a></li>
  75.                                 <li><a href="" target="_self">Property & Accomodation</a></li>
  76.                                 <li><a href="" target="_self">Precious Stones & Metals</a></li>
  77.                                 <li><a href="" target="_self">Information Technology</a></li>
  78.                                 <li><a href="" target="_self">Insurance</a></li>
  79.                             </ul>
  80.                         </div>
  81.                     </li>
  82.                 </ul>
  83.             </div>
  84.         </div>
  85.  
  86.         <div align="center">
  87.             <table width="100%" height="35" align="center" bgcolor="#000">
  88.                 <tr>
  89.                     <td>
  90.                         <div class="menu">
  91.                             <?php
  92.                             // display below statement for informational purposes only, will later integrate conditions.
  93.                             print "....Coordinates Loaded....";
  94.                             ?>
  95.                         </div>
  96.                     </td>
  97.                 </tr>
  98.             </table>
  99.         </div>
  100.  
  101.         <!-- map start -->
  102.  
  103.         <div class="menu2">
  104.             <?php
  105.             // kosher_london_bakeries.php code
  106.             ini_set('display_errors', 1);
  107.  
  108.             error_reporting(E_ALL);
  109.  
  110.             $username = "***";
  111.             $password = "***";
  112.             $hostname = "cust-mysql-123-02";
  113.             $connect = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
  114.  
  115.             $selected = mysql_select_db("***", $connect) or die("Could not select ***");
  116.  
  117.             // run query on listings table returning matching category and areagroup
  118.             $result1 = mysql_query("
  119.                 SELECT CategoryID1, Company, Latitude, Longitude, AreaGroup, Streetno, Address, Locality, City, PostalCode, PhoneNumber
  120.                 FROM DirectoryListings
  121.                 WHERE CategoryID1 ='420' AND AreaGroup = 'London' AND Latitude <> 0
  122.                 ORDER BY Company ASC
  123.             ");
  124.  
  125.             /*
  126.              * Changes by Werelds:
  127.              * - Got rid of most variables; wasting time copying values when you can just use them straight up
  128.              * - Got rid of the "counters" - just start from index 0 to keep things consistent
  129.              * - PHP doesn't require an index when setting array values; you can push to an array by using []
  130.              * - Refactored variable names into full names for clarity :P
  131.              */
  132.             $companies = array();
  133.  
  134.             // Simply store each row in an array
  135.             while ($row = mysql_fetch_array($result1)) {
  136.                 $companies[] = $row;
  137.             }
  138.  
  139.             /*
  140.              * At this point $companies looks like this:
  141.              * array(
  142.              *   array(
  143.              *     'Latitude' => xx.xxxxxx,
  144.              *     'Longitude' => xx.xxxxxx,
  145.              *     'Company' => 'Company 1',
  146.              *   ),
  147.              *   array(
  148.              *     'Latitude' => xx.xxxxxx,
  149.              *     'Longitude' => xx.xxxxxx,
  150.              *     'Company' => 'Company 2',
  151.              *   ),
  152.              * )
  153.              *
  154.              * And so on. Note that AreaGroup and all the other fields are also in these arrays of course.
  155.              */
  156.             ?>
  157.         </div>
  158.  
  159.         <div id="map_canvas"></div>
  160.  
  161.         <!-- Footer -->
  162.  
  163.         <div align="center" class="footer">
  164.             Copyright Data Analyst Limited
  165.         </div>
  166.  
  167.         <!--
  168.             Fixed by Werelds: Moved this to the very bottom, as that's customary :)
  169.             Keep JS at the very bottom of document body so that it always loads last.
  170.         -->
  171.         <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  172.         <script type="text/javascript">
  173.             /*
  174.              * Now the awesome part: json_encode will turn the array above into an array of objects
  175.              * An associative array in PHP (like the ones for each row above) becomes an object.
  176.              *
  177.              * This now allows you to actually do all of the JS work in JS.
  178.              * The example array above will now be encoded to the following JSON:
  179.              * [
  180.              *   { "Latitude" => xx.xxxxxx, "Longitude" => xx.xxxxxx, "Company" => "Company 1" },
  181.              *   { "Latitude" => xx.xxxxxx, "Longitude" => xx.xxxxxx, "Company" => "Company 2" },
  182.              * ]
  183.              *
  184.              * This way you can avoid mixing PHP and JS, which is rarely a good idea.
  185.              */
  186.             var companies = <?php echo json_encode($companies); ?>;
  187.             var markers = new Array();
  188.             var map;
  189.  
  190.             var markerClick = function (event) {
  191.                 // Nasty, but we have to do it like this :(
  192.                 for (var i = 0; i < companies.length; i++) {
  193.                     var company = companies[i];
  194.                     var marker_coordinates = new google.maps.LatLng(company.Latitude, company.Longitude);
  195.  
  196.                     // Compare to the clicked LatLng
  197.                     if (marker_coordinates.equals(event.latLng)) {
  198.                         map.setCenter(marker_coordinates);
  199.                         map.setZoom(16);
  200.  
  201.                         var infowindow = new google.maps.InfoWindow({
  202.                             content: '<b>' + company.Company + '</b><br><br>Index: ' + i + ''
  203.                         });
  204.  
  205.                         infowindow.open(map, markers[i]);
  206.                     }
  207.                 }
  208.             };
  209.  
  210.             function initialize() {
  211.                 var myOptions = {
  212.                     zoom: 10,
  213.                     center: new google.maps.LatLng(51.5, -0.18),
  214.                     mapTypeId: google.maps.MapTypeId.ROADMAP
  215.                 };
  216.  
  217.                 map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  218.  
  219.                 // Add each marker
  220.                 for (var i = 0; i < companies.length; i++) {
  221.                     var company = companies[i];
  222.  
  223.                     markers[i] = new google.maps.Marker({
  224.                         position: new google.maps.LatLng(company.Latitude, company.Longitude),
  225.                         title: company.Company,
  226.                         map: map
  227.                     });
  228.  
  229.                     // Don't forget to attach markerClick() to each of them
  230.                     google.maps.event.addListener(markers[i], 'click', markerClick);
  231.                 }
  232.             }
  233.         </script>
  234.     </body>
  235. </html>
Advertisement
Add Comment
Please, Sign In to add comment