Hello,
i want ask somthing about mysql in multi pages i hope someone help me
and sorry about my English

this code works good but there problem if i used it with this tybe

sql = "SELECT * FROM emaillogs ORDER BY id DESC"
                cursor.execute(sql)
                results = cursor.fetchall()
                if page <= "1":
                    for row in results[0:30]:
                        print row

                else: 
                    NUM2 = int(page) * 30
                    NUM1 = NUM2 - 30
                    for row in results[int(NUM1):int(NUM2)]:
                        print row

and the page link will be domain.com/file.py?do=emaillogs&page=1

this code if big data in table will cause load and long time to process because the sql code will get all rows in the table in memory and python code "for row in results[0:30]:" will show after that 30 only in the page at browser
i want code get data limit direct from mysql code

It seems that you must use the LIMIT keyword in the SELECT statement, as described in the mysql documentation. For example

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15

See also this. I dont know how it will interact with your ORDER BY clause.

yes i know this but how can do this with Variables ?
I mean as you said and also this works

"SELECT * FROM emaillogs WHERE id BETWEEN 10 AND 15 ORDER BY id DESC"

but i want use Variables like this
link:
domain.com/file.py?do=emaillogs&limit1=5&limit2=10

"SELECT * FROM emaillogs WHERE id BETWEEN 10 AND 15 ORDER BY id DESC"

How recoup BETWEEN 10 AND 15 in Variables ?

when i use this appear to me error : "SELECT * FROM emaillogs WHERE id BETWEEN '%s' AND '%s' ORDER BY id DESC" %(limit1,limit2)

i hope you understand me

Try

sql = ("SELECT * FROM `emaillogs`"
    " WHERE `id` BETWEEN {i1:d} AND {i2:d}"
    " ORDER BY `id` DESC").format(
        i1 = int(limit1), # type checking with conversion
        i2 = int(limit2),
    )

your code works good
really thank you so much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.