Error using implode () function

[B]
I am just trying to upload gps routes with this application – http://trekhotel.com/bina/upload.php , however there are happens an unexpected bug in the query with PHP function and MySQL database.
The php function source code used for the points
upload in the database is that - geodb.class.php :


 <?php 
     function inputRouteTrack($routeId, $points) { 
      $query = "INSERT INTO `geo_points` (`id`, `route`, `lat`, `lng`, 
`alt`, `time`)"; 

              foreach($points as $p) { 
    $pnts[] = "(NULL, $routeId, '".floatval($p->lat)."', 
       '".floatval($p->lng)."', '".floatval($p->alt)."', '".intval($p->time)."')"; 


                } 
                $query .= " VALUES ".implode(',',$pnts); 

                $res = $this->query($query); 


                return $this->affected; 
        } 
?> 

The MySQL dump for the table below :


 -- phpMyAdmin SQL Dump 
-- version 3.2.4 
-- http://www.phpmyadmin.net 
-- 
-- Server: localhost 
-- Time: Fev 24, 2010  06:12 PM 
--  Server version : 5.0.89 
--  PHP version : 5.2.9 

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; 

CREATE TABLE IF NOT EXISTS `geo_points` ( 
  `id` int(11) NOT NULL auto_increment, 
  `route` int(11) NOT NULL default '0', 
  `lat` float NOT NULL default '0', 
  `lng` float NOT NULL default '0', 
  `alt` float NOT NULL default '0', 
  `time` int(11) NOT NULL default '0', 
  PRIMARY KEY  (`id`) 
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9540 ; 

The XML file uploaded very well , however the inserting
points ( lat,lng ) into table failed and return these
errors :

"Warning: Invalid argument supplied for foreach() in /home/trekhote/
public_html/bina/core/geodb.class.php on line 221

Warning: implode() [function.implode]: Invalid arguments passed in /
home/trekhote/public_html/bina/core/geodb.class.php on line 224
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘’ at line 1 "

I make var_dump($pnts) to debug and it returns NULL.
Please if someone can help me about thank you very
much !
Djalma Bina.
[/B]

$points is empty, the problem is before this code is even reached

[B]
Thank you very much for the answer.
I insert this code in the function :
— if(empty($points) || !is_array($points)) return false; —

 
   <?php  
 function inputRouteTrack($routeId, $points) {   
	     if(empty($points) || !is_array($points)) return false;
		$query = "INSERT INTO `geo_points` (`id`, `route`, `lat`, `lng`, `alt`, `time`)";

              foreach($points as $p) {
			$pnts[] = "(NULL, $routeId, '".floatval($p->lat)."', '".floatval($p->lng)."', '".floatval($p->alt)."', '".intval($p->time)."')";
		        
               }   
                  
		$query .= " VALUES ".implode(',',$pnts);
		
		$res = $this->query($query);
		
		return $this->affected;
	} 
<? 

Very well this fix the error and now upload the GPS files however IT IS NOT BROWSING THE TRAIL correctly , now the messages are :

Warning: Wrong parameter count for max() in /home/trekhote/public_html/bina/core/georoute.class.php on line 40

Warning: Wrong parameter count for max() in /home/trekhote/public_html/bina/core/georoute.class.php on line 41

Warning: Wrong parameter count for max() in /home/trekhote/public_html/bina/core/georoute.class.php on line 42

Warning: Wrong parameter count for min() in /home/trekhote/public_html/bina/core/georoute.class.php on line 43

Warning: Wrong parameter count for min() in /home/trekhote/public_html/bina/core/georoute.class.php on line 44

Warning: Wrong parameter count for min() in /home/trekhote/public_html/bina/core/georoute.class.php on line 45

http://trekhotel.com/bina/index.php?r=42

The georoute.class.php :


<?php

class Route {
	var $points; //array with points
	
	var $lats; //array with latitudes
	var $maxlat; 
	var $minlat;
	
	var $lngs; //array with longitudes
	var $maxlng;
	var $minlng;
	
	var $alts; //array with elevations 
	var $maxalt;
	var $minalt;
	 
	var $n; 
	var $dist; //total distance in metres
	var $drop; //total drop in metres
	var $time; //time the route spent in secconds
	var $hours;
	var $minutes;

	function fromPoints($points) {   
	    
	
		$this->n = count($points); 
                 
		
		for($i = 0; $i < $this->n; $i++) {
			$this->lats[$i] = $points[$i]->lat;
			$this->lngs[$i] = $points[$i]->lng;
			$this->alts[$i] = $points[$i]->alt;
		}
		//max and min
		$this->maxlat = max($this->lats);
		$this->maxlng = max($this->lngs);
		$this->maxalt = max($this->alts);
		$this->minlat = min($this->lats);
		$this->minlng = min($this->lngs);
		$this->minalt = min($this->alts);
		
		$this->drop = $this->getDrop($points);
		$this->dist = $this->getTotalDistance($this->lats,$this->lngs,$this->alts);
		$this->time = $points[($this->n-1)]->time - $points[0]->time;
		$this->hours = floor($this->time / 3600);
		$this->minutes = floor(($this->time - 3600 * $this->hours) / 60);
	}

	     
	function getDrop($points) // returns total drop in 
	{
		$n = count($points);
		$drop = 0;
	 	for($i = 1; $i < $n; $i++)
	 	{
			if($points[$i]->alt > $points[($i-1)]->alt) 
				$drop += round($points[$i]->alt - $points[($i-1)]->alt);
		}
		return $drop;
	}
	function distAB($lat1,$lng1,$alt1,$lat2,$lng2,$alt2) { //returns the distance in metres between two points
		$distKM = 6371000 * acos(cos(deg2rad($lat1))*cos(deg2rad($lat2))*cos(deg2rad($lng2)-deg2rad($lng1))+sin(deg2rad($lat1))*sin(deg2rad($lat2)));
		$dist = sqrt(pow($distKM,2)+pow(($alt1-$alt2),2));
		return $dist; 
	}
	function getTotalDistance($lats,$lngs,$alts) { //returns total distance in meters
		$step = 1;
	 	$total = count($lats);
	
		$a = $b = $c = 0;
		
		//this algorithm takes the max and the min difference distances, to calculate a pitagoric distance at the end
		for($i = $step; $i < $total; $i += $step) {
			$latn = abs($lats[$i]-$lats[$i-$step]);
			$lngn = abs($lngs[$i]-$lngs[$i-$step]);
			$a += max($latn,$lngn);
			$b += min($latn,$lngn);
			$c += abs($alts[$i]-$alts[$i-$step]);
		}
		return $this->distAB(0,0,0,$a,$b,$c);
	}
}
?>

It seems me something with the $points also.

thanks .

[/B]

“max($this->lats);” won’t work, because max() takes a list of params, not an array.

Also, is there a reason you bold every post? It is damn annoying.

Please what parameters must be used there ?
thanks.