[Mapserver-users] listing field names of my $oShape->values; (Because it's Friday???)

Dylan Keon keon at nacse.org
Fri Feb 27 13:53:36 PST 2004


Denis,

$oShape->values is an associative array.  Asking for $flds[$fieldcount] 
will give you nothing since the keys are not a numeric index.

Try replacing your "for" loop with this:

	foreach($oShape->values as $key=>$value) {
		echo "$key = $value<br>\n";
	}

Just echo $key to get the field names only.

--Dylan



FX Gamoy wrote:
> hello
> try
> print_r($oShape);
> or
> print_r($oShape->values);
>  
> fx gamoy
> http://www.mapxplore.com/
>  
> 
>     ----- Original Message -----
>     *From:* Denis Lalonde <mailto:denlalonde at yahoo.com>
>     *To:* mapserver-users at lists.gis.umn.edu
>     <mailto:mapserver-users at lists.gis.umn.edu>
>     *Sent:* Friday, February 27, 2004 9:34 PM
>     *Subject:* [Mapserver-users] listing field names of my
>     $oShape->values; (Because it's Friday???)
> 
>     Hello all,
>     I'm simply trying to get a list of the field names of a layer...
>     I'm using php & mapscipt 4 and accessing my MapInfo data (OGR)
>     Here's my code that's not working (I get "Undefined offset" error
>     when accessing the array):
>     I have my results and my layer set; the result of my echo
>     sizeof($flds) is 20 which is good. The item that I am querying does
>     have data in all 20 fields.
> 
>                         $oRes = $oLayer->getResult($iRes);
>                         $oShape = $oLayer->getShape(-1,$oRes->shapeindex);
>                        
>                         $flds=$oShape->values;
>                         echo "numfields: ".sizeof($flds)."<br>";
>                         for ($fieldcount=0; $fieldcount < sizeof($flds);
>     $fieldcount++)
>                             {
>                                echo $flds[$fieldcount];
>                             }
>      
>     should that not spit me out my field names?
>      



More information about the MapServer-users mailing list