Jump to content

Inserting values into database using for loop?


python72

Recommended Posts

Is it possible to use for loop to insert values into database using for loop?

Or what would be the another way to insert these values into the database if the number of values being entered differs from one time to another? Here is basically what I am trying to do:

mysql_query("INSERT INTO MaxMillionsNum SET
Day='$weekday',
DrawDate='$CompleteDate',
DateTime='$timestamp',
for($i=1; $i<=$SetNumber; $i+=1){
for($j=0; $j<7; j+=1){
$NumberName="Number".$i.$v[$j];//Generating name of database field
$$NumberName=$Match[0][$j];//Here I would store the $Match value into the fieldname name created above
}
}
Tries='$RunCounter'");

You have field names that are a series of named/numbered/named values.

 

The reason thorpe asked is because that generally indicates you are trying to make a database act like a spreadsheet and this results in more code, hard to write queries, and poor performance.

I figured name is a name, just trying to separate sets of numbers so they are easier to view when I look at the database. I guess the easiest way to have arrays but as far as I know it is not possible within mysql. Not sure what would be the best way to do it so that is what I chose to do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.