ich wollte mit folgenden code eine tabelle erstellen die id's x-y und für diese id ist in der db ein type zugeteit, zb grass oder stein, aber wenn cih abfrage, kommt immer nur das heraus:
Code: Alles auswählen
<td id="1-1" class="[]"></td>
Code: Alles auswählen
#!D:/Python33/python.exe
#print('#!/usr/bin/python')
import sqlite3
print("Content-type:text/html\r\n\r\n")
print('''
<html>
<head>
<title>Terracraft</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link href='http://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
</head>
<body>
</body>
</html>
''')
db = 'map.db'
connection = sqlite3.connect(db)
print('<span class="ok">Database: Connected</span> <span class="little">Connected to DB: ', db, '</span><br>')
cursor = connection.cursor()
cont = '<table>'
x = 0
y = 0
while y < 100:
y += 1
cont += '<tr>'
while x < 100:
x += 1
v_id = '{}-{}'.format(x,y)
sql = '''SELECT type FROM map WHERE id=''' + v_id
try:
cursor.execute(sql)
except sqlite3.Error as e:
print('<span class="err">Database: SQL Error</span> <span class="little">Error: ', e.args[0], '</span><br>')
row = cursor.fetchall()
cont += '<td id="{}" class="{}"></td>'.format(v_id, row)
x = 0
cont += '</tr>'
cont += '</table>'
print(cont)