title: PHP Insert multiple rows in split batches
body: <p>I have a query to insert multiple rows in split batches. Basically, I need to split inserts in batches so that I can generate a unique random ID to the inserted batch.</p>
  
  <p>What I've tried and failed with many different options, one of them as follow.</p>
  
  <pre><code>$batch = 150;
  $sql = "SELECT DISTINCT `column` FROM `table` GROUP BY `column` ORDER BY `ID` ASC";
  $sqle = $con-&gt;Execute($sql);
  $results = $sqle-&gt;getrows();
  for($i=0; $i&lt;count($results);$i++){
      $columns1 = $results[$i]['column'];
        if($i==$batch){
              $randd = randcode(5).time();
                  $sql = "INSERT INTO `newtable` SET `columns1` = ".$con-&gt;qstr($columns1).", `rcode` = ".$con-&gt;qstr($randd).", `DATE_PUBLISHED` = ".$con-&gt;qstr($sdate);
                  $results=$con-&gt;Execute($sql);
             $i=0;
          }
  }
  </code></pre>
  
  <p>However, am not successful in inserting unique code to every 150 batch inserted query. </p>
  
  <p>Where am I going wrong in generating random unique code for every batch? And also I would like to know if there is less than 150 records, then how to handle the same?</p>