Database to Web

Simon Faulkner news at titanic.co.uk
Fri Jan 14 14:04:52 EST 2000


Has anyone got a good sugestion for the easiest way to display the
results of an sql query on a web page?

This works but it's not pretty!

TIA

def listdetails():
  db =MySQLdb.connect(host="localhost",db='BTC',user="root",passwd="")
  cursor = db.cursor()
  cursor.execute("SELECT * FROM tblDetail WHERE lngSalesPersonID=30")
  tuple = cursor.fetchall()
  total = len(tuple)
  if total < 1:
    print "No entries"
  else:
    print "Content-type: text/html\n"
    print "<H3>DETAILS</H3>"
    print "<P>"
    print "<table border cellspacing=0 cellpadding=5>"
    for record in range(total):
      Name =  tuple[record]
      print "<tr>"
      print Name
      print "</tr>"
    print "</table>"
  db.close()

Simon



More information about the Python-list mailing list