title: looping on mysql query
body: <p>im busy with a script to load mysql data in php variablen.</p>
  
  <p>My database is an gps tracking database with different users and gps coordinates in a table.
  The problem is. each gps update has its own ID... for an example if userA posting his gps location that will be id 1, but when user B also post their location 5 minutes later this is id 2, when userA post their location again 10 minutes later, that will be id 3.</p>
  
  <p>Now is the question. How can i sort the newest gps locations for each user.</p>
  
  <p>This is my table structure and my code:</p>
  
  <pre><code>//Tabel selecteren en wat opties defineren
  $posities = mysqli_query($raw,"SELECT * FROM positions INNER JOIN devices ON positions.device_id = devices.id ORDER BY positions.id DESC");
  
  //Aantal gebruikers tellen in de devices tabel aanroepen via $aantalgb
  $query = mysqli_query($raw,"SELECT COUNT(id) FROM devices");
  $row = mysqli_fetch_row($query); 
  $aantalgb = $row[0]; 
  mysqli_free_result($query); 
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  &lt;th&gt;ID&lt;/th&gt;
  &lt;th&gt;Naam&lt;/th&gt;
  &lt;th&gt;Tijd&lt;/th&gt;
  &lt;th&gt;Lat&lt;/th&gt;
  &lt;th&gt;Lon&lt;/th&gt;
  &lt;th&gt;Snelheid&lt;/th&gt;
  &lt;/tr&gt;";
  while($pos = mysqli_fetch_array($posities)) {
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;" . $pos['device_id'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $pos['name'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $pos['time'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $pos['latitude'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $pos['longitude'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $pos['speed'] . "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  }
  echo "&lt;/table&gt;";
  </code></pre>
  
  <p>Thank you!</p>