为此查询查询两个表


Query Two Tables for this query

我更专注于我的特定查询,而不是如何执行它

查询

伪~SELECT * FROM site_locations WHERE "There is an audit in 'audits' with that particular site location

因此,它们将分别成为

SELECT * FROM site_locations

SELECT site_locations FROM audits

因此,在对该站点位置的审计中,选择*进行审计的站点位置。

然而,对于特定的站点位置,audits中可能有多个审计,所以我只需要返回一个计数。

完整

$query = "SELECT * FROM site_locations";
$stmt = $db->prepare($query);
$stmt->execute();
?>
<?php 
    $points = array();
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $lat = json_encode($row['latitude']);
        $long = json_encode($row['longitude']);
        $site = json_encode($row['site_name']);
        $point = new stdClass();
        $coords = array();
        $coords[] = floatval($row['latitude']);
        $coords[] = floatval($row['longitude']);
        $point->latLng = $coords;
        $point->name = $row['site_name'];
        array_push($points, $point);
    }
?>
<script>
var points = <?php echo json_encode($points); ?>;
</script>
<script type="text/javascript">
function initMap() {
    $('.map').vectorMap({
        map: 'world_mill_en',
        scaleColors: ['#C8EEFF', '#0071A4'],
        normalizeFunction: 'polynomial',
        hoverOpacity: 0.7,
        hoverColor: false,
        zoomOnScroll: false,
        markerStyle: {
            initial: {
                fill: '#F8E23B',
                stroke: '#383f47'
            }
        },
        regionStyle: {
            initial: {
                fill: '#9f9f9f',
                "fill-opacity": .9,
                stroke: '#fff',
            },
            hover: {
                "fill-opacity": 0.7
            },
            selected: {
                fill: '#1A94E0'
            }
        },
        markerStyle: {
            initial: {
                fill: '#e04a1a',
                stroke: '#FF604F',
                "fill-opacity": 0.5,
                "stroke-width": 1,
                "stroke-opacity": 0.4,
            },
            hover: {
                stroke: '#C54638',
                "stroke-width": 2
            },
            selected: {
                fill: '#C54638'
            },
        },
        backgroundColor: '#f1f4f9',
        markers: points
    });
}
</script>
SELECT * FROM site_locations WHERE site_name in (SELECT site FROM audits)

上述查询将返回审核中有一个条目的所有site_location(每个位置一个计数(。