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'");

Link to comment
Share on other sites

You cannot use a PHP for loop within an SQL query. Use a loop to build your queries if necessary, but you can't actually use them in a query.

 

Ive asked you this before but, why do your database fields all have id's appended to them?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.