如何使用pyqt在标签上显示数据计数

时间:2017-10-02 07:50:07

标签: pyqt4

self.pushButton786.clicked.connect(self.refresh)

def refresh(self):

    db = MySQLdb.connect('localhost', 'root', 'Suhel786', 'project')
    cursor = db.cursor()
    a=cursor.execute("select count(*) from donor")
    b=cursor.execute("select count(*) from customer")
    c=str(a)
    d=str(b)
    self.label_8.setText(c)
    self.label_9.setText(d)
    db.close()

即使数据库中没有数据,这也总是1 ...

1 个答案:

答案 0 :(得分:0)

DROP TABLE IF EXISTS my_table;

CREATE TABLE my_table
(minor INT NOT NULL
,checkin TINYINT NOT NULL
,created  DATETIME NOT NULL
,PRIMARY KEY(minor,created)
);

INSERT INTO my_table VALUES
(3002,0,'2017-09-29 18:07:38'),
(3002,0,'2017-09-29 18:07:46'),
(3002,0,'2017-09-29 18:07:52'),
(3002,1,'2017-09-29 18:08:22'),
(3002,1,'2017-09-29 18:08:44'),
(3002,1,'2017-09-29 18:08:52'),
(3002,1,'2017-09-29 18:09:04'),
(3002,0,'2017-09-29 18:09:48'),
(3002,0,'2017-09-29 18:12:14'),
(3002,0,'2017-09-29 18:14:44'),
(3002,1,'2017-09-29 18:21:32'),
(3002,0,'2017-09-29 18:21:40'),
(3002,0,'2017-09-29 18:21:48'),
(3002,0,'2017-09-29 18:22:14');

SELECT checkin
     , created 
  FROM 
     ( SELECT x.*
            , CASE WHEN @prev <> checkin THEN @stamp:=created END stamp
            , @prev:=checkin prev 
         FROM my_table x
            , (SELECT @prev:=null,@created:=null) vars 
        ORDER 
           BY created
     ) a
 WHERE stamp IS NOT NULL
 ORDER 
    BY created;

+---------+---------------------+
| checkin | created             |
+---------+---------------------+
|       1 | 2017-09-29 18:08:22 |
|       0 | 2017-09-29 18:09:48 |
|       1 | 2017-09-29 18:21:32 |
|       0 | 2017-09-29 18:21:40 |
+---------+---------------------+