There is a page where the location of the relevant company is displayed on a map from the regional search, but two of the same companies are displayed on some pages.

Asked 1 years ago, Updated 1 years ago, 242 views

There is a page where the location of the relevant company is displayed on a map from the regional search, but two of the same companies are displayed on some pages.
Example) Search results xx
·Company A
·Company B
·Company C
·Company A

I got the address, longitude, and latitude from the DB and displayed GoogleMap in JS, but I don't know why.

DB It has been confirmed that there is only one applicable company information in DB
2 Some pages are displayed as expected without getting two.

<script type="text/javascript" charset="utf-8">
// <![CDATA[
varsidebar_html="";
varmarksers=[];
varmarker_html = [ ];
var counter = 0;
varicon=Array();

function initialize() {    
    vari = 0;
    <?php while($facility=mysql_fetch_array($result)){?>
        if(i==0){
            // Google Map map location (latitude and longitude of the center point of the map)
            if(<?=$sm?>==3){
                var init_pos = new google.maps.LatLng(<?=$facility['lat']?>,<?=$facility['lng']?>);
                var init_zoom=15;
            } else {
                var init_pos = new google.maps.LatLng (35.653735, 139.637003);
                var init_zoom=13;
            }

            // Set map options
            varmyOptions={
                zoom —init_zoom, // Zoom degree setting
                center —init_pos, // Set the latitude and longitude of the center of the map
                navigationControl:true, // display zoom navigation
                mapTypeControl:true, // Display map type switching
                scaleControl:true//displaying scale
            };
            // GoogleMap Maps
            vargmap = new google.maps.Map( document.getElementById("map_canvas"), myOptions);
        }

        //Pin the map
        varpoint = new google.maps.LatLng(<?=$facility['lat']?>,<?=$facility['lng']?>);
        vargmarker = new google.maps.Marker({
            position:point,
            map: icon[i],
        });

        // Display a list of locations
        variable_name="<?=$facility['name']?><\/a><?=$facility['address']?>";
        var maphtml = "<div class=\"mapinfo\"><a href=\"shika.php?shika_id=<?= $facility['shika_id'] ?><?= $back ?>\"><?= $facility['name'] ?><\/a><br \/><span style=\"font-size:13px;\">休診日:<?= $facility['holiday'] ?><br \/>所在地:<?= $facility['address'] ?><br \/>TEL:<?= $facility['tel'] ?></span><br\/><a href=\"shika.php?shika_id=<?=$facility['shika_id']?>?=$back?>\">>Learn more<\/a><\/div>";;";

        markers [counter] = gmarker;
        marker_html [counter] = maptml;
        if(i<<?=$num_rows?>){
            sidebar_html+='<div class=\"mapside\">a href=\"javascript:click_sidebar('+counter+')\">'+title_name+'<\/div>';;;;';
        }
        counter++;

        Displaying //map
        gmarker.setMap(gmap);
        i++;
    <?php
    }
    if($sm=='3'){
        $sql="select*from`shika_data`where`chiku_id`='.mysql_real_escape_string($_GET['chiku'])."' and `shika_id`>=1 order by `cyoume`asc";

        $result=mysql_query($sql);
        $num_rows = mysql_num_rows($result);

        while($facility=mysql_fetch_array($result)){?>
            //Pin the map
            varpoint = new google.maps.LatLng(<?=$facility['lat']?>,<?=$facility['lng']?>);
            vargmarker = new google.maps.Marker({
                position:point,
                map: icon[i],
            });

            // Display a list of locations
            variable_name="<?=$facility['name']?><\/a><?=$facility['address']?>";
            var maphtml = "<div class=\"mapinfo\"><a href=\"shika.php?shika_id=<?= $facility['shika_id'] ?><?= $back ?>\"><?= $facility['name'] ?><\/a><br \/><span style=\"font-size:13px;\">休診日:<?= $facility['holiday'] ?><br \/>所在地:<?= $facility['address'] ?><br \/>TEL:<?= $facility['tel'] ?></span><br\/><a href=\"shika.php?shika_id=<?=$facility['shika_id']?>?=$back?>\">>Learn more<\/a><\/div>";;";

            markers [counter] = gmarker;
            marker_html [counter] = maptml;
            if(i<<?=$num_rows?>){
                sidebar_html+='<div class=\"mapside\">a href=\"javascript:click_sidebar('+counter+')\">'+title_name+'<\/div>';;;;';
            }
            counter++;

            Displaying //map
            gmarker.setMap(gmap);
            i++;
        <?php
        }
    }
    ?>

    document.getElementById("sidebar_map").innerHTML=sidebar_html;
    /* alert("You cannot view Google Maps with your browser settings.<br\/> Please check your Javascript settings and re-enter the page."); */
}
function click_sidebar(idx){
    var infoWindow = new google.maps.InfoWindow({
        content: marker_html [idx]
    });
    infoWindow.open(marker_html[idx], markers[idx]);

}
//]]>
</script>

javascript php

2022-09-30 21:56

1 Answers

The cause is
This is because I do not understand the specification of mysql_fetch_array correctly.
mysql_fetch_array

Returns an array of strings representing the retrieved row.Returns false if the line does not exist.The format of the array returned depends on how the result_type is specified.MYSQL_BOTH (default) retrieves an array with both associative and numeric subscripts.

If you do not specify a value for the second argument, both associative subscripts and numeric subscripts are passed.
Therefore, the actual code is

$facility=mysql_fetch_array($result)

$facility=mysql_fetch_array($result,MYSQL_NUM)

Or

$facility=mysql_fetch_array($result,MYSQL_ASSOC)

Use the or use a dedicated function.
mysql-fetch-assoc
mysql-fetch-row


2022-09-30 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.