2011-09-19 82 views
2

如何将python-cgi输出分割成页面。 样品环结构:Python CGI:如何将大量输出分割成页面?

尽管1:

if x is true: 
    c.execute("select m from n where id=%s") 
    gene=c.fetchall() 
    print "%s", (gene), 
else: 
    print "NA" 

if y is true: 
    c.execute("select p from q where id=%s") 
    protein=c.fetchall() 
    print "%s", (protein), 
else: 
    print "NA" 

print "\n" 

输出是数以百万计的线。我想将输出分解成页面,比如每页50行。我怎么做?我感谢您的帮助。谢谢。

回答

0

使用“LIMIT offset,limit”sql语句。你也可以缓冲你的输出,并写入数据通过网页打破它(文件)

+0

我想,我不能修改该选择命令,因为我具有其中将一排打印出环路多个选择命令。你有链接到示例代码? – Sushil

+0

你是否需要来自每个sql请求或所有数据响应的50行?如果你有多个sql,你可以像这样设置限制:Limit offset,round(50/number_of_sql_queries) –

3

草图如何进行:

  1. 你有一个参数page代码到你的网址,这表明“显示页码page“。这与http://xxx.abc.de/genes?page=3类似,您必须修改脚本才能检索此参数。这可以使用http://docs.python.org/library/urlparse.html#

  2. 您必须修改您的选择,以便检索元素page ... page+pagesize-1。 MySQL对此具有limit修饰符。请参阅http://dev.mysql.com/doc/refman/5.1/en/select.html

  3. 您必须在页面上生成链接,该链接指向前一页和以下链接(如果存在)。根据以上这个例子是http://xxx.abc.de/genes?page=2http://xxx.abc.de/genes?page=4