我更依赖于我的特定查询,而不是如何做到这一点
查询
伪〜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>
答案 0 :(得分:1)
SELECT * FROM site_locations WHERE site_name in (SELECT site FROM audits)
上述查询将返回所有在审计中都有条目的site_locations(每个的一个计数)。