2 回答
TA贡献1835条经验 获得超7个赞
用于获取下一个视频的 USe 限制和偏移量
CREATE TABLE videos (
`id` INTEGER,
`filename` VARCHAR(8),
`program_id` INTEGER
);
INSERT INTO videos
(`id`, `filename`, `program_id`)
VALUES
('1', 'vid1.mp4', '1001'),
('2', 'vid2.mp4', '1010'),
('3', 'vid3.mp4', '1005');
✓
✓
SELECT * FROM videos ORDER BY program_id ASC LIMIT 1 OFFSET 0;
id | filename | program_id
-: | :------- | ---------:
1 | vid1.mp4 | 1001
SELECT * FROM videos ORDER BY program_id ASC LIMIT 1 OFFSET 1;
id | filename | program_id
-: | :------- | ---------:
3 | vid3.mp4 | 1005
SELECT * FROM videos ORDER BY program_id ASC LIMIT 1 OFFSET 2;
id | filename | program_id
-: | :------- | ---------:
2 | vid2.mp4 | 1010
db<>在这里
i = 0
while true:
sql = "SELECT * FROM videos ORDER BY program_id ASC LIMIT 1 OFFSET "+str(i);
cnx.execute (sql)
result = cnx.fetchall()
for qq in result:
id = qq[0]
filename = qq[1]
program_id = qq[3]
i = i +1
playVideo(filename)
但是,由于您只得到一行,因此您不需要 for 循环。
此外,您还需要一个断点来离开 While 循环,例如,当不再有行时。
TA贡献1794条经验 获得超7个赞
我真的看不出运行单独的查询来获取此处的每一行有什么意义。
您可以简单地运行单个查询,该查询为您提供按增加排序的视频,然后循环访问查询结果:program_id
while true:
sql = "SELECT * FROM videos ORDER BY program_id"
cnx.execute (sql)
result = cnx.fetchall()
for qq in result: -- fetch each video, ordered by "programm_id"
id = qq[0]
filename = qq[1]
program_id = qq[3]
playVideo(filename) -- play this video
添加回答
举报