title: limit a query result to a specific row
body: <p>Assume I get an array from mysql in php that contains the following items:</p>
  
  <blockquote>
    <p>A, B, B, B</p>
  </blockquote>
  
  <p>I do a foreach on the array and examine each item. For each item I run a query that returns another value. On the first item I have no problem since the following query returns just one item:</p>
  
  <pre><code>SELECT id, id_ogg FROM rischiatura WHERE id_ruolo = 'RU010000003' AND id_ndg = '$ndg'
  </code></pre>
  
  <p>where the $ndg value is taken from the array. So in the first run I get id_ndg = 'A'.</p>
  
  <p>In the other runs the query returns each time three results (it is ok -  three same items in the array = three rows returned from this query). 
  My issue is:
  <strong>inside the foreach loop how to run this query limiting the result to the first returned row the first time, the second in the second run and the third in the third run?</strong> </p>
  
  <p>The starting point is:</p>
  
  <pre><code>foreach($items as $ndg){
      SELECT id, id_ogg FROM rischiatura WHERE id_ruolo = 'RU010000003' AND id_ndg = '$ndg';
  }
  </code></pre>
  
  <p>I am looking for some code that will work both with A that is a single item and for B that will return each time one of the three results.</p>