[Tutor] If loop not executing completely

Sharriff Aina NHYTRO@compuserve.com
Thu, 3 May 2001 08:09:47 -0400


Hi guys, I coded a CGI script with database access:

## code ##
#------------------------------------------------------------------------=
--
-----
connection =3D odbc.odbc('minicms')
cur =3D connection.cursor()
cur.execute("select templatetype from userpages where username =3D'%s'"
%(usernamevalue))
usertemplate =3D cur.fetchall()
cur.close()
connection.close()
# cleanup and choose css
#
-------------------------------------------------------------------------=
--
---
tempusertemplate =3D usertemplate[0]
usertemplate =3D tempusertemplate[0]
if usertemplate =3D=3D 'template1':
....htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir + =

'template1.css')
elif usertemplate =3D=3D 'template2':
.... htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir +
'template2.css')
.... # and so on #

since I=B4m adding images too:

## code
if usertemplate =3D=3D 'template1':
    htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template1.jpg')
elif usertemplate =3D=3D 'template2':
    htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template2.jpg')
.... # and so on...

I decided to couple both actions together

#   final code ##
tempusertemplate =3D usertemplate[0]
usertemplate =3D tempusertemplate[0]
if usertemplate =3D=3D 'template1':
....htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir + =

'template1.css')
....htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template1.jpg')
elif usertemplate =3D=3D 'template2':
.... htmlhead =3D string.replace(htmlhead, '<usercss>', templatedir +
'template2.css')
.... htmlhead =3D string.replace(htmlhead, '<topbar>', templatedir + =

'template2.jpg')


this promptly causes a "list out of range error" !!??? I switched back to=

chugging along the string to be replaced separately. =


Sorry to nag you guys


Thanks

Sharriff