我使用foreach语句获取所有数据并打印在表中,并使用ajax获取该区域的所有区域和驱动程序,每行根据其来源有不同的驱动程序但问题是当我加载页面时它向我显示所有用户数据只在表中,但区域和驱动程序只显示我一行其他行不显示我的驱动程序下面是我的代码请告诉我我错在哪里
<tbody>
<?php
$counter = 0;
foreach($result as $user){?>
<form action="<?php echo SURL?>dashboard/set_driver" method="POST">
<tr>
<td><?php get_username($user['client_id']); ?></td>
<td><?php echo $user['pickfrom']; ?></td>
<td><?php echo $user['dropat']; ?></td>
<td><?php echo $user['pickdate'].' '.$user['picktime']; ?></td>
<td><?php echo $user['distance']; ?></td>
<input type="hidden" id="txtSource" value="<?php echo trim($user['pickfrom']); ?>">
<td>
<div class="form-group">
<select class="form-control" name="driver_id" id="drivers_<?php echo $counter;?>"><option>Select Driver</option>
</select>
</div></td><input type="hidden" id="latitude" name="latitude" value="<?php echo $user['latitude'];?>">
<input type="hidden" id="longitude" name="longtitude" value="<?php echo $user['longtitude'];?>">
<input type="hidden" name="request_id" value="<?php echo $user['id'];?>">
<td>
<button class="btn btn-default" name="submit">Set Driver</button>
</td>
</tr>
</form>
<?php echo $div_id = '#drivers_'.$counter;?>
<script>
var map;
var coord1 = new google.maps.LatLng(<?php echo $user['latitude'];?>, <?php echo $user['longtitude'];?>);
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(33.714760, 73.083160),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
<?php
$counter=0;
if(!empty($zone)){
foreach($zone as $findzone)
{
$exploded_data=explode('),',$findzone['zone_latlog']);
$count=count($exploded_data);
$zone_id = $findzone['id'];
?>
var bermudaTriangle = new google.maps.Polygon({
map: map,
paths: [
<?php
for($i=0;$i<$count;$i++){
echo "new google.maps.LatLng".$exploded_data[$i]."),";
}
?>
]
});
var bounds = new google.maps.LatLngBounds();
for (var i=0; i<bermudaTriangle.getPath().getLength(); i++) {
bounds.extend(bermudaTriangle.getPath().getAt(i));
}
bounds.extend(coord1);
var marker1 = new google.maps.Marker({
map: map,
position: coord1
});
map.setCenter(bounds.getCenter());
map.setZoom(11);
var result = checkInPolygon(marker1, bermudaTriangle);
if(result)
{
var zone_id = <?php echo $zone_id;?>;
alert(zone_id);
var lati = $('#latitude').val();
var longi = $('#longitude').val();
$.ajax({
url: '<?php echo SURL;?>dashboard/check_driver/<?php echo $zone_id;?>/'+longi+'/'+lati,
data: 'zone_id='+ zone_id+'&lati='+lati+'&longi='+longi,
type: "POST",
dataType: 'json',
cache: false,
success: function(response) {
// alert(response);
for(var i = 0; i < response.length; i++) {
alert(response[i].driver_name);
$('<?php echo $div_id?>').append($('<option>', {
value: response[i].driver_id,
text: response[i].driver_name
}));
}
}
});
}
<?php
}}?>
}
function checkInPolygon(marker, polygon) {
var infowindow = new google.maps.InfoWindow();
var html = "";
if (google.maps.geometry.poly.containsLocation(marker.getPosition(), polygon)) {
return true;
} else {
return false;
}
infowindow.setContent(html);
infowindow.open(map, marker);
}
</script>
<?php
$counter++;
}
?>
</tbody>
如果我在foreach之外编写脚本,我会向我显示驱动程序的单个数据,如果我在内部写入结果是相同的。
答案 0 :(得分:0)
更改你的foreach循环使其成为动态,首先计算结果,然后将其传递给数组块,然后传递给你的数字的for循环,并在其中传递一个foreach