[mapserver-users] php mapscript

Sven Schroeter schroeter at netgis.de
Thu Mar 25 09:18:50 EDT 2010


Hi,
I have an old php mapscript code that works fine with mapserver 5.02 or 5.2, 
but not with 5.6.1.
The code runs an attribute tabe from a postgis layer and different querys 
i.e. queryByRect:

...
@$datQuery = $query_layer->queryByRect($qRect);

 //number of objects
 $resnum = $query_layer->getNumResults();
 echo "number of objects: ".$resnum."<br>";

 //if query success
if ($datQuery == MS_SUCCESS) {
  $query_layer->open();

  //first row
  $result = $query_layer->getResult(0);
  $shpobj = $query_layer->getShape($result->tileindex,$result->shapeindex);
  //read attribute
  $attr = $shpobj->values;

  //write headline
  echo '<table cellspacing="0" cellpadding="2" border="1" ><tr>';
  foreach($attr as $name=>$wert) {
   echo '<td bgcolor="#CCCCCC">'.$name.'</td>';
  }
  echo '</tr>';

  //write datasets
  for ($j=0; $j<$query_layer->getNumResults(); $j++) {
   $result = $query_layer->getResult($j);
   $shpobj = $query_layer->getShape($result->tileindex,$result->shapeindex);
   $ri = $result->tileindex;
   $si = $result->shapeindex;
   $attr = $shpobj->values;
   echo '<tr id="row'.$si.'" >';
   foreach($attr as $name=>$wert) {
    echo '<td>'.$wert.'</td>';
   }
   echo '</tr>';
   $shpobj->free();
  }
  $query_layer->close();
  echo '</table>';

} // end success
...

In ms 5.6.1 the query is also successful (I get the correct number of 
objects) but there comes following warning:
Invalid argument supplied for foreach() in ... Fatal error: Call to a member 
function free() on a non-object in ...
No object? Why? What has changed?
Thanks
Sven 





More information about the mapserver-users mailing list