Advertisement
Guest User

Untitled

a guest
Nov 5th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import pymssql
  2. import itertools
  3.  
  4. connection = pymssql.connect(server="192.168.1.1", user="Me", password="password", port=1234, database="Blue")
  5. cur = connection.cursor()
  6. cur.execute('SELECT * FROM testtable')
  7. varone = cur.fetchall()
  8. connection.close()
  9. hope = list(itertools.chain(*varone))
  10.  
  11. def print_table(data, row_length):
  12. counter = 0
  13. for element in data:
  14. if counter % row_length == 0:
  15. print ('<tr>')
  16. print ('<td align="center">%s</td>' % element)
  17. counter += 1
  18. if counter % row_length == 0:
  19. print ('</tr>')
  20. if counter % row_length != 0:
  21. for i in range(0, row_length - counter % row_length):
  22. print ('<td align="center">&nbsp;</td>')
  23. print ('</tr>')
  24.  
  25. print ('Content-type:text/htmlrnrn')
  26. print ('<!DOCTYPE HTML>')
  27. print ('<html lang="en">')
  28. print ('<meta charset="UTF-8">')
  29.  
  30. print ('<head>')
  31. print ('<title>Table Example</title>')
  32. print ('<style>table {width: 40%} table, th, td {border: 1px solid black} </style>')
  33. print ('</head>')
  34. print ('<body>')
  35.  
  36. print ('<table>')
  37.  
  38. print ('<tr>')
  39. print ('<th>First Name</th>')
  40. print ('<th>Last Name</th>')
  41. print ('<th>Date</th>')
  42. print ('<th>Random Number</th>')
  43. print ('</tr>')
  44.  
  45. print_table(hope, 4)
  46.  
  47. print ('</table>')
  48.  
  49. print ('</html>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement