Python Forum
pyMySQL - ROW_NUMBER in SQL statement - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: pyMySQL - ROW_NUMBER in SQL statement (/thread-25600.html)



pyMySQL - ROW_NUMBER in SQL statement - JayCee - Apr-05-2020

Hello everyone,

Greetings from Brazil! I'm trying to navigate through a MySQL database using pyMySQL and a GUI form to display the data, but when I press the 'Previous' button, for example, it prints the correct row number in the console, but the form doesn't display the previous record. Any ideas on what I am doing wrong?

This is what I have tried:

def ShowPrevious(self):
    global rowNo
    sql = "SELECT @row_no AS row_number, name, email, pwd, market FROM users WHERE (@row_no:=%s) ORDER BY name"
    cur.execute(sql, rowNo)
    row = cur.fetchone()
    if rowNo <= cur.rowcount:
        print("Row", rowNo, "is the first record.")
    elif row:
            ui.lineEdit_name.setText(row[1])
            ui.lineEdit_email.setText(row[2])
            ui.lineEdit_pwd.setText(row[3])
            ui.lineEdit_market.setText(row[4])
            rowNo -= 1
            print(rowNo)
    else:
        rowNo += 1
Thank you very much for your time and help. I really appreciate it.

Best regards and stay well.


RE: pyMySQL - ROW_NUMBER in SQL statement - JayCee - Apr-12-2020

I SOLVED THE PROBLEM. Check the link below to see my solution:

https://python-forum.io/Thread-PyQt-Tutorial-Python-and-pymsql-database-navigation

Thanks.