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
https://forums.phpfreaks.com/topic/249474-insert-using-a-loop/
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
https://forums.phpfreaks.com/topic/249474-insert-using-a-loop/#findComment-1281055
Share on other sites

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.