title: CSV import only for certain amount then exceed data go into another table
body: <p>I have a problem here. I don't know how to give an appropriate question title. So here is my problem. </p>
  
  <p>I have a set of csv data. Let's say 30 data. The condition is I want only 20 data goes to Table A and another 10 data goes to Table B.</p>
  
  <p>Do you have any example on how to work with this logic? Can it be done by combining while loop and if statement? By the way, it is a PHP and I'm still a newbie programmer. Hopefully someone can help me. Thank you.</p>
  
  <p>Edited:
  My current code</p>
  
  <pre><code>while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
  {
      if($leftPax &gt; 0)
      {
          $registrantBean = new z_EventRegistrants();
          $registrantBean-&gt;last_name = $data[1];
          $registrantBean-&gt;id_no = $data[0];
          $registrantBean-&gt;phone_mobile = $data[2];
          $registrantBean-&gt;email1 = $data[3];
          $registrantBean-&gt;gender = $data[4];
          $registrantBean-&gt;date_of_birth = $data[5];
          $registrantBean-&gt;age = $data[6];
          $registrantBean-&gt;race = $data[7];
          $registrantBean-&gt;z_eventregec5erations_ida = $registrationBean-&gt;id;
          $registrantBean-&gt;save();
          $count++;
          error_log(print_r($_REQUEST['session'], 1));
          foreach($_REQUEST['session'] as $aid=&gt;$sid)
          {
              $attendanceBean = new z_EventAttendances();
              $attendanceBean-&gt;name = $registrantBean-&gt;last_name;
              $attendanceBean-&gt;z_eventsessions_z_eventattendancesz_eventsessions_ida = $sid;
              $attendanceBean-&gt;z_eventactivities_z_eventattendances_1z_eventactivities_ida = $aid;
              $attendanceBean-&gt;z_eventregistrations_z_eventattendancesz_eventregistrations_ida = $registrationBean-&gt;id;
              $attendanceBean-&gt;z_eventregistrants_z_eventattendancesz_eventregistrants_ida = $registrantBean-&gt;id;
              $attendanceBean-&gt;save();
          }
      }
      else
      {
          $waitlistBean = new z_EventWaitlists();
          $waitlistBean-&gt;name = $data[1];
          $waitlistBean-&gt;save();
      }
  }
  </code></pre>
  
  <p>What I want, the 20 data will go to z_EventRegistrants and the other 10 will go to z_EventWaitlist.</p>