title: How to pass variable into MySQLdb query with Python?
body: <p>I'm trying to loop over an MySQL query, however I can't get the variable to work. What am I doing wrong? The loop starts at line 10.</p>
  
  <pre><code>cur = db.cursor()
  query = '''
  Select user_id, solution_id 
  From user_concepts
  Where user_id IN 
    (Select user_id FROM fields);
  '''    
  cur.execute(query)
  numrows = cur.rowcount
  for i in xrange(0,numrows):
      row = cur.fetchone()
  # find all item_oid where task_id = solution_id for first gallery and      sort by influence.
      cur.execute('''
          SELECT task_id, item_oid, influence
          FROM solution_oids 
          WHERE task_id = row[%d]
          ORDER BY influence DESC;
          ''', (i))
      cur.fetchall()
  </code></pre>
  
  <p>error message:</p>
  
  <blockquote>
    <p>File "james_test.py", line 114, in ''', (i))
    File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line 187, in execute
    query = query % tuple([db.literal(item) for item in args])
    TypeError: 'int' object is not iterable</p>
  </blockquote>