Python Forum
How to save specific variable in for loop in to the database?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to save specific variable in for loop in to the database?
#2
Is that your full query?
If you are able to do your select against the same table, in your example = FROM Win32_ComputerSystem

Then you should be able to insert all those values into the DB per loop.

It would be better if you are able to provide a little more code that you are using or trying to better assist..

example i found online..
mycursor = mydb.cursor()

sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"
val = ("John", "Highway 21")
mycursor.execute(sql, val)

mydb.commit()
I think providing more of your code would help.. im sure its just something that needs to be reorganized so that each loop inserts that set of data values.
Reply


Messages In This Thread
RE: How to save specific variable in for loop in to the database? - by cubangt - Mar-09-2022, 10:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 450 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,763 Nov-07-2023, 09:49 AM
Last Post: buran
  how to save to multiple locations during save cubangt 1 564 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Pymodbus read and save to database stewietopg 3 1,882 Mar-02-2023, 09:32 AM
Last Post: stewietopg
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,605 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  loop (create variable where name is dependent on another variable) brianhclo 1 1,149 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Multiple Loop Statements in a Variable Dexty 1 1,212 May-23-2022, 08:53 AM
Last Post: bowlofred
Big Grin Variable flag vs code outside of for loop?(Disregard) cubangt 2 1,189 Mar-16-2022, 08:54 PM
Last Post: cubangt
  How to add for loop values in variable paulo79 1 1,460 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  Get latest version off website and save it as variable [SOLVED] AlphaInc 5 1,990 Nov-14-2021, 09:00 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020