title: Python/MySQL: Select data in a for loop
body: <p>I apologize if it seems like I am having some trouble putting my problem into words. Basically, I am programming a messaging system where the user can send messages to other users and view their messages in an inbox. Here are some screenshots of what my database and GUI look like:
  <a href="http://imgur.com/a/ra5Di" rel="nofollow">http://imgur.com/a/ra5Di</a></p>
  
  <p>This is my function for displaying the messages in the inbox:</p>
  
  <pre><code>#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)
                      FROM Message m
                      INNER JOIN SentMessage s ON m.id = s.messageID
                      WHERE s.recipient = %s""", (recipient))
      rows = cursor.fetchall()
  
      i = 3
      for 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
  </code></pre>
  
  <p>This is my function for displaying the message and its content after the user has clicked on "View/Reply." Note that it is selecting a specific message ID and not the one I actually want it to display. In other words, it's just placeholder.</p>
  
  <pre><code>#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)
                  FROM Message m
                  INNER JOIN SentMessage sm ON m.id = sm.messageID
                  WHERE 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)
  </code></pre>
  
  <p>So my problem is this... I want the user to be able to click on "view/reply" and view the corresponding message, and not just a placeholder. I don't even know how to begin solving this problem. I think that what I want to do is get the message id from a specific row in displayMessageInfo's for loop, but I'm not entirely sure. Any ideas?</p>