title: for loop in for loop, python, csv reader/writer
body: <p>I am new in python, but after 3 days of reading and finding solution without success i am lost. </p>
  
  <p>I've got mysql table with data (id, user_id...). I connect to db, read user_id and save data into array "user". Then i open csv file with a lot of rows and columns (user_id, name, mail, telephone, address...). In the next step i compare if user_id from db matches with user_id in csv file. If answer is yes then i write this row in another csv file. </p>
  
  <p>Problem is that my code works only for first id_user.  Please, can you help me?</p>
  
  <p><strong>Example table:</strong></p>
  
  <pre><code>table in db:
  id     user_id
  1      318604
  2      318624
  </code></pre>
  
  <p><strong>csv file:</strong> </p>
  
  <pre><code>318604;    John;    john@gmail.com
  318604;    053746;  USA 
  318624;    Lucy;    Lucy@gmail.com
  318624;    058839   Sweeden
  318630;    Luke;    Luke@gmail.com
  </code></pre>
  
  <p><strong>Expected result in new file:</strong></p>
  
  <pre><code>318604;    John;    john@gmail.com
  318604;    053746;  USA 
  318624;    Lucy;    Lucy@gmail.com
  318624;    058839   Sweeden
  </code></pre>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>cur = con.cursor()
  with open('input.csv', mode='rb') as f:
      reader = csv.reader(f, delimiter=';')
      with open('output.csv', mode='a') as w:  
          writer = csv.writer(w)
          with con:            
              cur.execute("SELECT user_id FROM users")
              user=cur.fetchall()            
              for i in range(len(user)):                               
                  for row in reader:
                      if(user[i][0]==row[0]):
                          writer.writerow(row)
  con.close()
  </code></pre>