9
Hi there! Will need help with this problem that i've been unabled to solve along 8 months. (Sorry for my english)
I have the admin LTE template installed, and I reorganized main_index.php to easy apply changes when needed related to the information I want to show on the page. Because of this, the map developed on the main_index is now written on a diferent .php and then added to the main index through an "include".
As I said on tittle, when there are more than one pilot fliying, only one (randomly) is show on the list, but every pilot is shown on the map.
This is the PHP:
===========================================
<head>
<?php
include('./db_login.php');
$db_map = new mysqli($db_host , $db_username , $db_password , $db_database);
$db_map->set_charset("utf8");
if ($db_map->connect_errno > 0) {
die('Unable to connect to database [' . $db_map->connect_error . ']');
}
$sql_map = "select r.flight as flightnum, plane_type, ias, flight_id,u.gvauser_id as gvauser_id,u.callsign as callsign,u.name as name,gs,altitude,surname, lf.departure as departure, lf.arrival as arrival, lf.latitude as latitude, lf.longitude as longitude, lf.flight_status as flight_status,lf.heading as heading,perc_completed, pending_nm, a1.latitude_deg as dep_lat, a1.longitude_deg as dep_lon , a2.latitude_deg as arr_lat, a2.longitude_deg as arr_lon , network from vam_live_flights lf, gvausers u, routes r, airports a1, airports a2 where u.gvauser_id=lf.gvauser_id and lf.departure=a1.ident and lf.arrival=a2.ident and r.route_id= u.route_id";
$sql_map = "select r.flight as flightnum,plane_type,ias,flight_id,u.gvauser_id as gvauser_id,u.callsign as callsign,u.name as name, gs,altitude,surname,lf.departure, lf.arrival,lf.latitude,lf.longitude,lf.flight_status,lf.heading,lf.perc_completed,
pending_nm, a1.latitude_deg as dep_lat, a1.longitude_deg as dep_lon , a2.latitude_deg as arr_lat, a2.longitude_deg as arr_lon , network
from vam_live_flights lf, gvausers u , airports a1, airports a2, routes r where u.gvauser_id=lf.gvauser_id and lf.departure=a1.ident and lf.arrival=a2.ident and r.route_id= u.route_id";
if (!$result = $db_map->query($sql_map)) {
die('There was an error running the query [' . $db_map->error . ']');
}
unset($flights_coordinates);
unset($flight);
unset($liveflights);
unset($datos);
unset($jsonarray);
$flights_coordinates = array();
$datos = array ();
$flight = array();
$liveflights = array ();
$jsonarray = array ();
$index = 0;
$index2=0;
$flightindex=0;
while ($row = $result->fetch_assoc()) {
$flight["gvauser_id"]=$row["gvauser_id"];
$flight["callsign"]=$row["callsign"];
$flight["flightnum"]=$row["flightnum"];
$flight["name"]=$row["name"];
$flight["gs"]=$row["gs"];
$flight["ias"]=$row["ias"];
$flight["altitude"]=$row["altitude"];
$flight["surname"]=$row["surname"];
$flight["departure"]=$row["departure"];
$flight["arrival"]=$row["arrival"];
$flight["latitude"]=$row["latitude"];
$flight["longitude"]=$row["longitude"];
$flight["flight_status"]=$row["flight_status"];
$flight["heading"]=$row["heading"];
$flight["dep_lat"]=$row["dep_lat"];
$flight["dep_lon"]=$row["dep_lon"];
$flight["arr_lat"]=$row["arr_lat"];
$flight["arr_lon"]=$row["arr_lon"];
$flight["perc_completed"]=$row["perc_completed"];
$flight["pending_nm"]=$row["pending_nm"];
$flight["network"]=$row["network"];
$flight["plane_type"]=$row["plane_type"];
$liveflights[$flightindex] =$flight;
$sql_map2 = "select * from vam_live_acars where flight_id='".$row["flight_id"]."' order by id desc";
if (!$result2 = $db_map->query($sql_map2)) {
die('There was an error running the query [' . $db_map->error . ']');
}
while ($row2 = $result2->fetch_assoc()) {
$flights_coordinates ["gvauser_id"] = $row2["gvauser_id"];
$flights_coordinates ["latitude"] = $row2["latitude"];
$flights_coordinates ["longitude"] = $row2["longitude"];
$flights_coordinates ["heading"] = $row2["heading"];
$datos [$index2][$index] = $flights_coordinates;
$index ++;
}
$index=0 ;
$index2 ++;
$flightindex ++;
}
$jsonarray[0]=$liveflights;
$jsonarray[1]=$datos;
?>
</head>
<div class="box box-primary direct-chat direct-chat-primary">
<div class="box-header with-border">
<i class="fa fa-location-arrow"></i>
<?php
$sql = 'select callsign, vf.arrival as arrival, vf.departure as departure, vf.flight_id as flight_id, vf.flight_status as flight_status, name, surname, pending_nm, plane_type, gu.route_id as route_id, ro.flight as flightnum from vam_live_flights vf, routes ro, gvausers gu where gu.gvauser_id = vf.gvauser_id and gu.route_id = ro.route_id group by callsign order by pending_nm asc ';
if (!$result = $db->query($sql)) {
die('There was an error running the query [' . $db->error . ']');
}
$row_cnt = $result->num_rows;
$sql = "SELECT flight_id FROM `vam_live_flights` WHERE UNIX_TIMESTAMP (now())-UNIX_TIMESTAMP (last_update)>180";
if (!$result = $db->query($sql)) {
die('There was an error running the query [' . $db->error . ']');
}
while ($row = $result->fetch_assoc())
{
$sql_inner = "delete from vam_live_acars where flight_id='".$row["flight_id"]."'";
if (!$result_acars = $db->query($sql_inner))
{
die('There was an error running the query [' . $db->error . ']');
}
$sql_inner = "delete from vam_live_flights where flight_id='".$row["flight_id"]."'";
if (!$result_acars = $db->query($sql_inner))
{
die('There was an error running the query [' . $db->error . ']');
}
}
if ($row_cnt>0){
?>
<h3 class="box-title"><?php echo "En el aire"; ?></h3>
</div>
<div class="panel-body;">
<div class="table-responsive">
<table class="table table-hover" id="live_flights_table">
<?php
echo "<tr><th>" . 'ID' . "</th><th>" . 'Piloto' . "</th><th>" . 'Origen' . "</th><th>" . 'Destino' . "</th><th>" . 'Etapa' . "</th><th>". 'Equipo' . "</th><th>" . 'Completado' ."</th><th>" . 'Millas restantes' . "</th></tr>";
echo '<td>';
echo $flight["callsign"] . '</td><td>';
echo $flight["name"] . ' ' . $flight["surname"] . '</td><td>';
echo $flight["departure"] . '</td><td>';
echo $flight["arrival"] . '</td><td>';
echo $flight["flight_status"] . '</td><td>';
echo $flight["plane_type"] . '</td><td>';
echo '<div class="progress progress-sm active">
<div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: ' . $flight["perc_completed"] . '%">
<span><data-label="90% completed"> '. $flight["perc_completed"] . '%' .' </span>
</div>
</div>' . '</td><td>';
echo $flight["pending_nm"] . 'NM ' . '</td>';
?>
</table>
</div>
<?php include ('./vam_live_flights_map.php') ?>
<br>
</div>
</div>
<?php
}
else {
?>
<h3 class="box-title"><?php echo "Sin pilotos en el aire"; ?></h3>
</div>
<div class="panel-body;">
<br>
<?php
}
?>
</body>
</html>
==================================
Thanks in advance