Prob. w/ Script Posting Last Value
Steve Holden
steve at holdenweb.com
Thu Apr 17 14:07:18 EDT 2008
Victor Subervi wrote:
> Hi;
> Gabriel provided a lovely script for showing images which I am modifying
> for my needs. I have the following line:
>
> print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
> where the correct values are entered for the variables, and those values
> increment (already tested). Here is the slightly modified script it calls:
>
>
> #!/usr/local/bin/python
> import cgitb; cgitb.enable()
> import MySQLdb
> import cgi
> form = cgi.FieldStorage()
> picid = int(form["id"].value)
> x = int(form["x"].value)
> pic = str(x)
> print 'Content-Type: text/html'
> db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
> cursor= db.cursor()
> sql = "select " + pic + " from products where id='" + str(picid) + "';"
> cursor.execute(sql)
> content = cursor.fetchall()[0][0].tostring()
> cursor.close()
> print 'Content-Type: image/jpeg\r\nContent-Length: %s\n' % len(content)
> print content
>
> I need to make it so that it will show all my images, not just the last
> one. Suggestions, please.
> TIA,
> Victor
>
In your "page generator" page, replace
print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
by
for d, y in (results of some DB query to get d and y for each image):
print '<img src="getpic.py?id=%d&x=%d"><br /><br /></td>\n' % (d, y)
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list