[postgis-users] Identifying field names in select out of order

Mark Cave-Ayland m.cave-ayland at webbased.co.uk
Tue Feb 21 08:59:09 PST 2006


 

> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net 
> [mailto:postgis-users-bounces at postgis.refractions.net] On 
> Behalf Of Sean M. Montague
> Sent: 21 February 2006 16:46
> To: PostGIS Users Discussion
> Subject: RE: [postgis-users] Identifying field names in 
> select out of order
> 
> Thanks Don,
> 
> I am using php. Problem with pg_fetch_assoc() is that I need 
> to know the field name.  I want to be able to get the field 
> name regardless of the order I select them in the select statement.
> 
> Sean


Hi Sean,

Here is a idea of the code that we would use to read column names and values
here. Note it's untested in its current form, but should give you an idea of
how to go about it.


<?

$dbstring = "host=x user=x password=x dbname=x";
$conn = pg_connect($dbstring);

$sql = "SELECT 'test1' AS string1, 'test2' AS string2";
$res = pg_query($conn, $sql);

for ($i = 0; $i < pg_num_rows($res); $i++)
{
	$row = pg_fetch_array($res, $i, PGSQL_ASSOC);

	foreach ($row as $field => $value)
	{
		echo "fieldname: " . $field . "<br>";
		echo "value    : " . $value . "<br>\n";
	}
}

?>


Kind regards,

Mark.

------------------------
WebBased Ltd
17 Research Way
Plymouth
PL6 8BT

T: +44 (0)1752 797131
F: +44 (0)1752 791023

http://www.webbased.co.uk   
http://www.infomapper.com
http://www.swtc.co.uk  

This email and any attachments are confidential to the intended recipient
and may also be privileged. If you are not the intended recipient please
delete it from your system and notify the sender. You should not copy it or
use it for any purpose nor disclose or distribute its contents to any other
person.





More information about the postgis-users mailing list