(newbie)cgi-problem --sorry, wrong file

Anders Dahlqvist dahqlvist at sundsvall.mail.telia.com
Fri Jun 6 09:40:10 EDT 2003


Here's the correct one, the other one was an old backup and wouldn't have
worked for obvious reasons. Apologies.

#!/usr/bin/env python

#Borde fungera med
http://loke/cgi-bin/python/funktioner.py?titel=Inskick&typ=inskick 
#men gör det inte
#Första gången något inte fungerar som tänkt i python!

import os,time,cgi,cgitb
from data import *

cgitb.enable()


def htmlstart(titel):
        print  htmlhuvud % (titel, titel, time.strftime("%F %X",time.localtime()))

def htmlstop():
        print htmlslut




def tabell(typ):
        if typ in lista0:
                tabellhuvud="<TABLE BORDER=1><TR><TH>databas</TH><TH>url</TH></TR>"
                html=os.popen("mysql --host=loke --user=apache arbeten --exec='select
databas,url from rekrytering where %s=1'" % typ).readlines() 
        elif typ in lista1:
                tabellhuvud="<TABLE
BORDER=1><TR><TH>databas</TH><TH>url</TH><TH>email</TH></TR>"
                html=os.popen("mysql --host=loke --user=apache arbeten --exec='select
databas,url,email from rekrytering where %s=1'" % typ).readlines()
        print tabellhuvud
        #Skapa en ny lista, innehållande listor med  varje rad i en egen lista
        lista=[]
        for rad in html:
                resrad=rad.replace('\n','')
                nyrad=resrad.split("\t")
                lista.append(nyrad)

        
        if typ in lista0:
                for underlista in lista[1:-1]:#Första raden ingår i tabellhuvud
                        print "<TR><TD>%s</TD><TD><A HREF='%s'>%s</A></TD></TR>" %
(underlista[0],underlista[1],underlista[1])
        elif typ in lista1:
                for underlista in lista[1:-1]:
                        print "<TR><TD>%s</TD><TD><A HREF='%s'>%s</A></TD><TD><A
HREF='mailto:%s'>%s</A></Td></TR>" %
(underlista[0],underlista[1],underlista[1],underlista[2],underlista[2])
        print tabellslut

if __name__=='__main__': 
        htmlstart(titel) #Alltså om programmet anropas med parametrar enligt ovan
        tabell(typ)
        htmlstop()





More information about the Python-list mailing list