Simple HTML display of a select query

Larry Bates larry.bates at websafe.com
Wed Aug 2 18:04:02 EDT 2006


flit wrote:
> Hi all,
> 
> How Can I do in the simplest way, display in html one table with the
> return of 3 collums?
> Like
> 1- consult mysql base
> 2- make the select query
> 3- show the values.
> 
> I am a kind of lost in the frameworks, and modules.
> I think a lot of them with little documentation.
> Just a simple display in html for this, nothing more.
> No need this time for right coding, if I need to remake the program in
> the future its ok..
> 
You don't do it much differently than you would to display them
on a regular screen or a piece of paper, except that you must wrap
the values in html table (not tested).  I hope I'm understanding
your question.

print "<table>"
print "<th>Column 1</th><th>Column 2</th><th>Column 3></th>"
for row in rowsreturnedbysqlquery:
    print "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" % \
          (row[0], row[1], row[2])

print "</table>

Now the fun comes when you wish to embellish this with font
sizes, colors, background colors, ....  then the frameworks
come in really handy.

-Larry Bates



More information about the Python-list mailing list