Python Forum
pyMySQL - ROW_NUMBER in SQL statement
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyMySQL - ROW_NUMBER in SQL statement
#1
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.
Reply
#2
I SOLVED THE PROBLEM. Check the link below to see my solution:

https://python-forum.io/Thread-PyQt-Tuto...navigation

Thanks.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pymysql can't do SELECT * Pedroski55 3 558 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  pymysql won't handle some diacritic characters awarren2001AD 0 575 Apr-16-2020, 08:58 AM
Last Post: awarren2001AD
  pyMySQL How do I get the row id JayCee 3 1,301 Apr-12-2020, 08:38 PM
Last Post: JayCee
  PyMySQL return a single dictionary Valon1981 2 822 Feb-20-2020, 04:07 PM
Last Post: Valon1981
  pymysql: formating ouput of query wardancer84 18 4,836 Oct-04-2018, 01:54 PM
Last Post: wardancer84
  pymysql ifnull aland 4 2,341 Sep-06-2018, 05:58 AM
Last Post: buran
  get last row id in pymysql tony1812 1 8,371 Sep-26-2017, 11:25 PM
Last Post: Larz60+
  pymysql question tony1812 1 1,895 Sep-26-2017, 12:41 AM
Last Post: Larz60+
  pymysql on macos seirra tony1812 5 2,864 Sep-17-2017, 03:24 PM
Last Post: Larz60+
  PyMySQL Dean Stackhouse 1 3,413 Oct-05-2016, 07:26 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020