hellouthere Posted March 4, 2007 Share Posted March 4, 2007 Script error... ill explain aftwerwards... <?php function Lat($position) { list ($n, $latmin, $w, $longmin) = explode (' ', $position); $nl = $n{0}; $nn = substr($n,1); $co = $latmin/60; if($nl == 'S') { $lat = -($nn+$co); }else{ $lat = $nn+$co; } return $lat; } function Long($position) { list ($n, $latmin, $w, $longmin) = explode (' ', $position); $wl = $w{0}; $wn = substr($w,1); $co = $longmin/60; if($wl == 'W') { $long = -($wn+$co); }else{ $long = $wn+$co; } return $long; } function DateAdd($interval, $number, $date) { $date_time_array = getdate($date); $hours = $date_time_array['hours']; $minutes = $date_time_array['minutes']; $seconds = $date_time_array['seconds']; $month = $date_time_array['mon']; $day = $date_time_array['mday']; $year = $date_time_array['year']; switch ($interval) { case 'y': case 'yyyy': $year+=$number; break; case 'q': $year+=($number*3); break; case 'm': $month+=$number; break; case 'd': case 'w': $day+=$number; break; case 'ww': $day+=($number*7); break; case 'h': $hours+=$number; break; case 'n': $minutes+=$number; break; case 's': $seconds+=$number; break; } $timestamp= mktime($hours,$minutes,$seconds,$month,$day,$year); return $timestamp; } //database details $hostName = "localhost"; $userName = "root"; $password = "********"; $dbName = "flkeeper"; //database connection $connect = @mysql_connect($hostName, $userName, $password); $select = @mysql_select_db($dbName); /* Delete not responding flights (LastMessage older than 30 minutes) */ $query = "DELETE FROM liveacars WHERE LastMessage <= ".date("YmdHis", DateAdd("n", -30, time())).";"; $result = mysql_query($query) or die("SQL query failed"); // Execute SQL query $query = "SELECT * FROM liveacars"; $result = mysql_query($query) or die("SQL query failed"); $number = mysql_num_rows($result); $id_file = fopen("cougarmark.xml","w+") or die("Cannot open XML File"); $text_file = "<"."?"."xml version=\"1.0\" encoding=\"ISO-8859-1\"". "?".">\n<markers>\n"; while ($row = mysql_fetch_array($result)) { switch ($row->Status) { case 0: $status = "Boarding"; $color = "black"; break; case 1: $status = "Taxiing"; $color = "blue"; break; case 2: $status = "Airborne"; $color = "green"; break; case 3: $status = "Landed"; $color = "red"; break; case 4: $status = "Parking"; $color = "gray"; break; } switch ($row->AltitudeStatus) { Case 0: $statusalt = "Descending"; break; Case 1: $statusalt = "Level off"; break; Case 2: $statusalt = "Climbing"; break; } if (strlen($row->Airline) != 0) { $airline = $row->Airline; } if (strlen($row->FlightNumber) != 0) { $fligtno = $row->FlightNumber; } $aircraft = $row->Aircraft; $callsign = $row->IDPilot; $realname = $row->PilotName; if (strlen($row->Passenger) != 0) { $pass = $row->Passenger; } if (strlen($row->Cargo) != 0) { $cargo = $row->Cargo; } if (strlen($row->FlightPlan) != 0) { $CurrentWP = $row->CurrentWaypoint; } /* ### Added v2.6 ### */ else { if (strlen($row->OriginAirport) != 0) { $dep = $row->OriginAirport; if (strlen($row->DestinationAirport) != 0) { $arr = $row->DestinationAirport; } } } /* ### Added v2.5 ### */ if ($row->PauseMode != 0) { $pause = "Paused"; }else { $pause = "OK"; } $position = $row->Position; $lat = Lat($position); $long = Long($position); if ($row->Heading != -1) { $hdg = $row->Heading; } if ($row->Altitude != -1) { $alt = $row->Altitude; } if ($row->IAS != -1) { $ias = $row->IAS; } if ($row->Status == 2 && $row->TAS != -1) { $tas = $row->TAS; /* ### Changed v2.6 ### */ if ($row->DistanceFlown != -1) { $distf = $row->DistanceFlown; if ($row->DistancePlanned > 0) { $distp = $row->DistancePlanned; } } } $text_file .= "<marker lng=\"".$long."\" lat=\"".$lat."\" title=\"".$realname."\" callsign=\"".$callsign."\" dep=\"".$dep."\" dest=\"".$arr."\" alt=\"".$alt."\" ias=\"".$ias."\" tas=\"".$tas."\" type=\"".$color."\" />\n"; } $text_file .= "\n</markers>"; fwrite($id_file,$text_file) or die("Cannot write to XML File"); fclose($id_file) or die("Cannot close XML file"); // Free resultsets mysql_free_result($result); // Close connection mysql_close($connect); ?> </body> </html> I get these errors... Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 114 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 141 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 156 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 160 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 164 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 165 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 166 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 167 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 171 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 175 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 180 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 189 Notice: Trying to get property of non-object in E:\www\cougar\map\mark.php on line 195 Notice: Undefined offset: 3 in E:\www\cougar\map\mark.php on line 7 Notice: Undefined offset: 2 in E:\www\cougar\map\mark.php on line 7 Notice: Undefined offset: 1 in E:\www\cougar\map\mark.php on line 7 Notice: Uninitialized string offset: 0 in E:\www\cougar\map\mark.php on line 9 The script is taking the data from the database, writing a header, then the body which is repeated for each record... then a footer, it is then writtten to an xml file.... Link to comment https://forums.phpfreaks.com/topic/41127-while-loops-and-xml/ Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 while ($row = mysql_fetch_array($result)) { switch ($row->Status) { case 0: $status = "Boarding"; $color = "black"; break; Try using mysql_fetch_object($result) as you are referencing $row as an object Link to comment https://forums.phpfreaks.com/topic/41127-while-loops-and-xml/#findComment-199346 Share on other sites More sharing options...
hellouthere Posted March 5, 2007 Author Share Posted March 5, 2007 thanks again barand, i changed it to array to try to make it work before, then realised that the database was actually empty, then forgot id changed it... Link to comment https://forums.phpfreaks.com/topic/41127-while-loops-and-xml/#findComment-199685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.