title: SQLite query returns values twice
body: <p>The SQL table consists of:</p>
  
  <pre><code>names:  id | firstName | lastName
  phones: id | phone1    | phone2   | phone3
  </code></pre>
  
  <p>The task is to show the registered users' first &amp; last names. Then, according to users' ID, show phone numbers (if they exist). In addition, I need to have an opportunity to expand the 'phones' table, so I can't just use string join because I am not aware of the amount of numbers.</p>
  
  <p>IMHO, it can be solved with foreach loop:</p>
  
  <pre><code>$stmt = $connection-&gt;prepare( 'SELECT firstName, lastName, id FROM names');
  $stmt-&gt;execute();
  foreach($stmt as $row)
  {
  
      $stmt = $connection-&gt;prepare( 'SELECT phone1, phone2, phone3 FROM phones WHERE id=?');
      $stmt-&gt;execute([$row['id']]);
      $number_str = '';
  
      foreach($stmt as $numbers)  // for each user's array of phones
      {
          foreach($numbers as $number) {  // for each phone in the array
              if($number) {
                  $number_str .= $number . ', ';  // build a string "phone1, phone2, phone3"
              }
          }
      }
      array_push($users, new User($row['firstName'], $row['lastName'], substr($number_str, 0, -2)));  // filling the array
  </code></pre>
  
  <p>Unfortunately, each user's number_str looks like: phone1, phone1, phone2, phone2 etc.</p>
  
  <p>Update:</p>
  
  <pre><code>$stmt = $connection-&gt;prepare( 'SELECT firstName, lastName, id FROM names');
  $stmt-&gt;execute();
  foreach($stmt as $row) {
  
      $stmt1 = $connection-&gt;prepare('SELECT phone1, phone2, phone3 FROM phones WHERE id=?');
      $stmt1-&gt;execute([$row['id']]);
      $a = $stmt1-&gt;fetch();
  
      $number_str = $a[0].$a[1].$a[2]; // phone1phone2phone3  -- works FINE, but why? btw, count($a) is 6, but I can't access $a[3]
      $number_str = implode(', ', $a); // phone1, phone1, etc
  
      array_push($users, new User($row['firstName'], $row['lastName'], $number_str));  // filling the array
  }
  </code></pre>