phpnerd Posted October 14, 2011 Share Posted October 14, 2011 Hello; I know! But how can I get the same results in a proper way without having to loop the query? <?php function createDatesArray($days) { $output = array(); $month = date("m"); $day = date("d"); $year = date("Y"); for($i=1; $i<=$days; $i++) { $output[] = date('Y-m-d',mktime(0,0,0,$month,($day+$i),$year)); } return $output; } $dates = createDatesArray("365"); foreach($dates as $d) { echo $query = "INSERT INTO DATES (day) VALUES ('".$d."')"; echo $d."<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2011 Share Posted October 14, 2011 You would form a multi-value insert query - INSERT INTO your_table (column_name) VALUES ('value1'),('value2'),('value3'),...,('valuen') You can form the value1'),('value2'),('value3'),...,('valuen by imploding the array with '),(' between each value. Quote Link to comment 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.