用python實現簡單翻頁

2021-08-20 07:53:22 字數 1350 閱讀 6669

一般情況下資料庫資料量太大的時候,不宜全部讀取到記憶體中。所以這裡做乙個簡單的上下翻頁的程式。

# !/usr/bin/python

# -*- coding:utf-8 -*-

# ++++++++++++++++++++

# author: fmspider

# time: 2018-5-28 13:54

# function: 翻頁

import pymysql

# 執行sql語句獲取資料庫資料

def sqlexec(last_nid,is_is):

conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='****', db='***', charset='utf8' )

cursor = conn.cursor(cursor=pymysql.cursors.dictcursor)

if is_is:

cursor.execute('select * from image where id>%s limit 10',last_nid)

result = cursor.fetchall()

else:

cursor.execute('select * from image where id<%s order by id desc limit 10 ', last_nid)

result = cursor.fetchall() # 獲取的資料是反的

result = list(reversed(result)) # 翻轉一下

conn.commit()

cursor.close()

conn.close()

return result

# 標誌位

current_lest_nid = 0

current_first_nid = 0

# 翻頁控制

while true:

if p == '2':

is_next = true

ret = sqlexec(current_lest_nid, is_next)

for i in ret:

print(i)

else:

is_next = false

ret = sqlexec(current_first_nid,is_next)

for i in ret:

print(i)

current_lest_nid = ret[-1]['id']

current_first_nid = ret[0]['id']

用儲存過程實現翻頁

use card db go object storedprocedure dbo pr get star user list v2 script date 03 05 2010 15 27 18 set ansi nulls on goset quoted identifier on go 查詢s...

Iphone實現簡單翻頁效果

經常看到iphone的軟體向上向下翻頁面的效果,其實這個很簡單,已經有封裝好的相關方法處理。首先設定動畫的相關引數 uiview beginanimations curl context nil uiview setanimationduration 1.25 時間 uiviewsetanimati...

listview 翻頁功能簡單實現

listview 翻頁功能簡單實現 includetypedef struct scroll scroll,p scroll 支援按單步移動和按頁移動 如果單步觸發了翻頁,整頁向上 下移動一步 void adjust scroll p scroll scroll int len 測試 int mai...