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 />"; } ?> Link to comment https://forums.phpfreaks.com/topic/249100-looping-query-is-nasty-how-can-i-remove-this-query-from-this-loop/ 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. Link to comment https://forums.phpfreaks.com/topic/249100-looping-query-is-nasty-how-can-i-remove-this-query-from-this-loop/#findComment-1279316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.