Jump to content

Insert using a loop


chrispos

Recommended Posts

Using MySQL 5

 

I am trying to use a loop to insert data

 

The tables are day, day1, month, year and price.

 

I have used a loop using day and day1 using php for the days and I know the months and year using a drop down menu. The idea is the user selects day then day1 and then the price and all that data is added.

 

days being 1 2 3 4 5 6 7 etc using php for the loop.

 

I can do a normal insert but is it posable to do this in sql using a loop?

 

Any help would be great

 

many thanks

Link to comment
Share on other sites

I have solved this using the code below if it helps someone.

$d = $_POST['d'];
$d1 = $_POST['d1'];
include 'config.php';
for ($i = $d; $i <= $d1; $i++)
{
$query = "INSERT INTO `test`(`day`) VALUES ('$i')";
    $result = mysql_query($query) or die (mysql_error());
echo "$i";
}

 

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.