title: Foreach with condition on a specific attribute?
body: <p>I have a database where I store publications:
  publication ID, Authors (priority is considered) and Publication title</p>
  
  <p>I am having trouble with the second foreach as I need a loop to generate authors' names before moving to the title. the query will bring the result fine like:</p>
  
  <p>PID Authors TITLE  </p>
  
  <p>1   NAME1 TITLE1     </p>
  
  <p>1   NAME2 TITLE1     </p>
  
  <p>1   NAME3 TITLE1     </p>
  
  <p>2   NAME1 TITLE2</p>
  
  <p>2   NAME2 TITLE2</p>
  
  <p>2   NAME3 TITLE2</p>
  
  <p>and so on</p>
  
  <p>I want the end result to be:</p>
  
  <p>1 NAME1, NAME2, NAME3 TITLE1</p>
  
  <p>2 NAME1, NAME2, NAME3 TITLE2</p>
  
  <p>here is my code:</p>
  
  <pre><code>foreach ($query-&gt;result() as $row)
    {
      echo $row-&gt;PID;
      echo ": ";
  
      foreach ($query-&gt;result() as $row)
        {
          echo $row-&gt;AUTHORS;
          echo ", ";
        }
  
      echo $row-&gt;TITLE;
      echo "&lt;br&gt;" . "&lt;br&gt;";
    }
  </code></pre>