On 5/30/06, Matthew Jarvis <[EMAIL PROTECTED]> wrote:
I'm trying to generate a php based report based on some postgres SELECT statements...
<snip details>
How do I assign the variables? Looking at the Postgres docs they have some sort of convoluted Function declarations going on. I'm not married to the idea of doing things this way, so I'm open to suggestions as well...
First thing I'd suggest is looking at the PHP docs rather than Postgres ones. They will likely be much more helpful. http://www.php.net/manual/en/ref.pgsql.php Assuming that you are at least mostly married to the idea of doing this with PHP, I'd suggest looking at using a database abstraction library in PHP to do the heavy lifting for you, rather than dealing with the SQL stuff directly. Overkill for what you are trying to accomplish _right now_, but might prove useful later on if you move to another DB backend, or you end up getting a lot of requests for reports it will make complex things much simpler. I'm no PHP expert, but most of the projects I've fiddled with use MDB2 ( http://oss.backendmedia.com/MDB2/HomePage ) for this sort of task. An easier solution for this particular problem would be to use the built-in PHP stuff for PostgeSQL. Not as scalable or general, but quick and easy. Something like this might work: ----------------code----------------------------------- <?php // Connecting, selecting database $dbconn = pg_connect("host=dbserver dbname=bikes user=www password=foo") or die('Could not connect: ' . pg_last_error()); // Performing SQL query $query = 'select count(*) from contacts where interest_touring'; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); // Printing results in HTML echo "<table>\n"; while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; // Free resultset pg_free_result($result); // Closing connection pg_close($dbconn); ?> ----------------------------end code ------------------------------- Note that the above was shamelessly lifted from the PHP example docs, with minor changes to make it a little more relevant to your situation. -- -Regards- -Quentin Hartman- _______________________________________________ EUGLUG mailing list [email protected] http://www.euglug.org/mailman/listinfo/euglug
