[Zope] Returning results from pythod method to web page

alankirk alankirk@genie.co.uk
Fri, 16 Mar 2001 10:15:13 -0000


This is a multi-part message in MIME format.

------=_NextPart_000_000F_01C0AE01.FD2DA040
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi there,

I'm trying to find a way of returning some results from a MySQL database =
search into a <OPTION> </OPTION> list in a web page.

I've written a python method which gets all the data i need from my =
database. I've stripped down the results (ie removed all the double and =
single quotes) so i can split them into the individual results.=20

Heres my problem, i've got a while loop that will loop through each of =
the results from my database query, but i need some way to pass these =
results out to my web page. I've tried using:

while (i<length):
  return "  <option value=3D\" "+splitString[i]+" \">"+splitString[i]+" =
"
  i =3D i + 1

Which works but as it uses Return it fall out the loop and only returns =
the one item in my OPTION list. So i then tried to return a string of =
all the search results such as:

while (i<length):
  f =3D "  <option value=3D\" "+splitString[i]+" \">"+splitString[i]+" "
  i =3D i + 1
  s =3D f
  s =3D s + f
return s

which returns the last item of the seach results. I've worked out that =
it does this because i keep overwriting the value of s with f. I've =
tried to assign s to be empty or " " but i was getting error messages =
saying s has not been assigned any values.

Does anyone know how i could get around this? or does anyone know a =
better way of returning values from a loop into a web page??

Any feedback (preferably ASAP) would be most apprieciated

Cheers

Alan
 =20

------=_NextPart_000_000F_01C0AE01.FD2DA040
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>Hi there,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm trying to find a way of returning =
some results=20
from a MySQL database search into a &lt;OPTION&gt; &lt;/OPTION&gt; list =
in a web=20
page.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I've written a python method which gets =
all the=20
data i need from my database. I've stripped down the results (ie removed =
all the=20
double and single quotes) so i can split them into the individual =
results.=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Heres my problem, i've got a while loop =
that will=20
loop through each of the results from my database query, but i need some =
way to=20
pass these results out to my web page. I've tried using:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>while (i&lt;length):<BR>&nbsp; return =
"&nbsp;=20
&lt;option value=3D\" "+splitString[i]+" \"&gt;"+splitString[i]+" =
"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; i =3D i + 1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Which works but as it uses Return it =
fall out the=20
loop and only returns the one item in my OPTION list. So&nbsp;i then =
tried to=20
return a string of all the search results such as:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>while (i&lt;length):</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; f =3D "&nbsp; &lt;option =
value=3D\"=20
"+splitString[i]+" \"&gt;"+splitString[i]+" "<BR>&nbsp; i =3D i + =
1<BR>&nbsp; s =3D=20
f<BR>&nbsp; s =3D s + f<BR>return s</DIV>
<DIV>&nbsp;</DIV>
<DIV>which returns the last item of the seach results. I've worked out =
that it=20
does this because i keep&nbsp;overwriting the value of s with f. I've =
tried to=20
assign s to be empty&nbsp;or " " but i was getting error messages saying =
s has=20
not been assigned any values.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Does anyone know&nbsp;how i could get around this? or does anyone =
know a=20
better way of returning values from a loop into a web page??</DIV>
<DIV>&nbsp;</DIV>
<DIV>Any feedback (preferably ASAP)&nbsp;would be =
most&nbsp;apprieciated</DIV>
<DIV>&nbsp;</DIV>
<DIV>Cheers</DIV>
<DIV>&nbsp;</DIV>
<DIV>Alan<BR>&nbsp; </FONT></DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_000F_01C0AE01.FD2DA040--