Python/MySQL: Select data in a for loop -



Python/MySQL: Select data in a for loop -

i apologize if seems having problem putting problem words. basically, programming messaging scheme user can send messages other users , view messages in inbox. here screenshots of database , gui like: http://imgur.com/a/ra5di

this function displaying messages in inbox:

#display message in inbox function def displaymessageinbox(mf, c, vm): recipient = config.nameinput cursor.execute("""select concat('title: ', m.title, '\n', 'from: ', s.sender, '\n', 'sent: ', s.timesent) message m inner bring together sentmessage s on m.id = s.messageid s.recipient = %s""", (recipient)) rows = cursor.fetchall() = 3 message in rows: messageinfo = tk.label(mf, text=message, bg="white", anchor=tk.w, justify=tk.left, width=30) messageinfo.grid(row=i, column=0, sticky=tk.w) viewreply = tk.button(mf, text="view/reply", anchor=tk.w, command=lambda:c.show_frame(vm)) viewreply.grid(row=i, column=1,padx=10, sticky=tk.w) i+=1

this function displaying message , content after user has clicked on "view/reply." note selecting specific message id , not 1 want display. in other words, it's placeholder.

#read message content function def readmessage(mf): mid = 'a6bb9c97-0f59-44ea-9f2b-759ffbac5031' cursor.execute("""select concat('from: ', sm.sender, '\n', 'title: ', m.title, '\n', 'message: ', m.content) message m inner bring together sentmessage sm on m.id = sm.messageid m.id = %s""", (mid)) rows = cursor.fetchone() message = rows[0] readmessagelabel = tk.label(mf, text=message, bg="white", anchor=tk.w, justify=tk.left, width=100) readmessagelabel.grid(row=3, column=0, padx=10, sticky=tk.w)

so problem this... want user able click on "view/reply" , view corresponding message, , not placeholder. don't know how begin solving problem. think want message id specific row in displaymessageinfo's loop, i'm not exclusively sure. ideas?

obviously, mid static value. need create variable dynamic passing value readmessage function conditional corresponding message after user presses 'view/reply'.

while don't know setup of app's interface controls consider: 1) querying message id, 2) save variable, 3) pass function. maybe started:

def displaymessageinbox(mf, c, vm): recipient = config.nameinput cursor.execute("""select m.id, concat('title: ', m.title, '\n', 'from: ', s.sender, '\n', 'sent: ', s.timesent) messagetxt message m inner bring together sentmessage s on m.id = s.messageid s.recipient = %s""", (recipient)) = 3 message in cursor.fetchall(): mid = message[0] messagetxt = message[1] ... if (viewreply == somevalue): # come in logic capture message user selected readmessage(mf, mid) def readmessage(mf, mid): cursor.execute("""select concat('from: ', sm.sender, '\n', 'title: ', m.title, '\n', 'message: ', m.content) message m inner bring together sentmessage sm on m.id = sm.messageid m.id = %s""", (mid)) rows = cursor.fetchone() message = rows[0] ...

python mysql database tkinter mysql-python

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -