chrispos Posted October 20, 2011 Share Posted October 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/249474-insert-using-a-loop/ Share on other sites More sharing options...
fenway Posted October 20, 2011 Share Posted October 20, 2011 Try again. Quote Link to comment https://forums.phpfreaks.com/topic/249474-insert-using-a-loop/#findComment-1280909 Share on other sites More sharing options...
chrispos Posted October 21, 2011 Author Share Posted October 21, 2011 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/249474-insert-using-a-loop/#findComment-1281055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.