[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-db
Subject:    Re: [PHP-DB] querying results from postgresql
From:       Stut <stuttle () gmail ! com>
Date:       2007-04-27 16:44:54
Message-ID: 46322886.6040806 () gmail ! com
[Download RAW message or body]

Kirk Wythers wrote:
> I am having trouble with a db query that was working not too long ago. I 
> did upgrade from php4 to php5 and wonder if there are some differences 
> that could explain my issue. Below is the code where I suspect things 
> are breaking down.
> 
> 
> // build sql query from form values
> $select_query = "select * from grid_cell where township = $township
> and range = $range and rdir_shortname = '$rdir_shortname'
> and section = $section and forty_name = '$forty_name'";
> //echo $select_query; // use for debugging sql query
> 
> // retrieve the query info from postgresql
> //this returns a resource, so put the resource into a variable
> $result = pg_query($select_query);
> //echo $result; // use for debugging sql query
> 
> // process results. First argument pg_result is the returned result set 
> ($grid_cell),
> // second argument is the row offset, and the third argument is the 
> column offset.
> $forty_grid = pg_result($result, 0, 0);
> //echo $forty_grid; // use for debugging sql query
> 
> 
> If I uncomment echo $select_query, the scrip prints the proper query 
> like this:
> 
> select * from grid_cell where township = 67 and range = 1 and 
> rdir_shortname = 'W' and section = 1 and forty_name = 'NWNW'
> 
> However, if I uncomment echo $result, the script prints:
> 
> Resource id #2
> 
> and also the error:
> 
> Unable to jump to row 0 on PostgreSQL result index 2
> 
> I think that the variable $result is getting the result from pg_query 
> and subsequently $forty_grid is not receiving what it expects either.
> 
> Does anyone see what I'm not doing right here?

Just because the query returned a resource ID does not mean it contains 
any results. An empty result set is what you're getting, and you need to 
check for that before trying to use the results.

-Stut

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic