Thread: Output HTML, or just a handle?

Output HTML, or just a handle?

From
"Rodolfo J. Paiz"
Date:
Hi!

Looking for "best practices" here. I've just seen that psql can output a
query to an HTML file. If I am creating a query within a web page, is it
generally recommended to get HTML output from PostgreSQL? If so, where
can I learn about how to put this in a query and how to control it with
finer-grained detail as regards column borders, fonts, etc?

Or is it recommended to just run the bare query, then use PHP on my
webpage to loop through the resulting output table handle and create the
table there? And if so, just so I don't reinvent the wheel more than
once a day, can someone point me to any code snippets previously written
on this? (That I can legally use, of course...)

Thanks for any advice. I promise not to post more questions tonight. :-)

Cheers,

--
Rodolfo J. Paiz <rpaiz@simpaticus.com>


Re: Output HTML, or just a handle?

From
Alexander Borkowski
Date:
Rodolfo,

> Looking for "best practices" here. I've just seen that psql can output a
> query to an HTML file. [...] Or is it recommended to just run the bare query, then use PHP on my
> webpage to loop through the resulting output table handle and create the
> table there? [...]

Depends on your application really and without more information there is
  nothing else I can say. For the vast majority of scenarios you
probably are better off using PHP (or some other language like Python,
Perl, Java, C, ...) and just loop through the result set. For PHP have a
look at

http://www.php.net/manual/en/ref.pgsql.php

Cheers,

Alex

Re: Output HTML, or just a handle?

From
Jason Dixon
Date:
On Jan 24, 2005, at 8:47 PM, Rodolfo J. Paiz wrote:

> Hi!
>
> Looking for "best practices" here. I've just seen that psql can output
> a
> query to an HTML file. If I am creating a query within a web page, is
> it
> generally recommended to get HTML output from PostgreSQL? If so, where
> can I learn about how to put this in a query and how to control it with
> finer-grained detail as regards column borders, fonts, etc?

I haven't used this much personally, so I'm probably not qualified to
give my two cents.  Of course, that's never stopped me before...

I believe this is just for outputting tables.  Looking at \?, I see
that you can alter the HTML tag attributes with \T.  However, there's
just something about dumping tables to a browser that feels... wrong.
Maybe that's just my paranoia speaking.  *shrug*

If PHP is what you're leaning towards (Perl!), then I would stick with
the PHP database handles.  Keep your presentation to the HTML and your
SQL to the database.

> Or is it recommended to just run the bare query, then use PHP on my
> webpage to loop through the resulting output table handle and create
> the
> table there? And if so, just so I don't reinvent the wheel more than
> once a day, can someone point me to any code snippets previously
> written
> on this? (That I can legally use, of course...)

This gets my vote.

--
Jason Dixon
DixonGroup Consulting
http://www.dixongroup.net



Re: Output HTML, or just a handle?

From
"Sean Davis"
Date:
I think psql adds the HTML and so isn't available via SQL.  In general, I
think "best practice" is to keep the database information separate from the
view of it (HTML is an example of a view of the data, but only one example).
As for reinventing the wheel, PHP is written to do just this (among other
things, but database access and display is by far the most common use, I
suggest without proof).  Any book worth half its weight will have such
examples.  Also, there are several websites devoted to this kind of thing.
Here is one from the top of a google search:

http://www.onlamp.com/pub/a/onlamp/2002/01/24/postgresql.html

Sean

----- Original Message -----
From: "Rodolfo J. Paiz" <rpaiz@simpaticus.com>
To: <pgsql-novice@postgresql.org>
Sent: Monday, January 24, 2005 8:47 PM
Subject: [NOVICE] Output HTML, or just a handle?


> Hi!
>
> Looking for "best practices" here. I've just seen that psql can output a
> query to an HTML file. If I am creating a query within a web page, is it
> generally recommended to get HTML output from PostgreSQL? If so, where
> can I learn about how to put this in a query and how to control it with
> finer-grained detail as regards column borders, fonts, etc?
>
> Or is it recommended to just run the bare query, then use PHP on my
> webpage to loop through the resulting output table handle and create the
> table there? And if so, just so I don't reinvent the wheel more than
> once a day, can someone point me to any code snippets previously written
> on this? (That I can legally use, of course...)
>
> Thanks for any advice. I promise not to post more questions tonight. :-)
>
> Cheers,
>
> --
> Rodolfo J. Paiz <rpaiz@simpaticus.com>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>



Re: Output HTML, or just a handle?

From
Alexander Borkowski
Date:
Rodolfo,

> Or is it recommended to just run the bare query, then use PHP on my
> webpage to loop through the resulting output table handle and create the
> table there? And if so, just so I don't reinvent the wheel more than
> once a day, can someone point me to any code snippets previously written
> on this?

As for not reinventing the wheel when it comes to database access in
PHP, I forgot to mention:

http://adodb.sourceforge.net/

and

http://pear.php.net/package/DB

Cheers,

Alex