title: Dynamically generating a RSS feed
body: <p>I might be thinking about this too deeply, but I'd still like to know if anybody has any strong opinions on it...</p>
  
  <p>I'm generating a news RSS feed using PHP. Each news story has many photos, which is reflected in my database structure with a 1:many relationship between the Stories and Photos tables.  This means I'm generating a results set which looks something like:</p>
  
  <p><kbd>StoryID</kbd><kbd>PhotoID</kbd><br/> 
  <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br/> 
  <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br />
  <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br />
  <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br /><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br />
  <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br />
  <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br />
  <kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd> <br /></p>
  
  <p>I'm generating a nested array to represent this more accurately:</p>
  
  <ul>
  <li>I'm generating this just using a <code>foreach</code> statement and <code>if</code> to see if the <code>StoryID</code> already exists when dealing with each new row - is there a better way? Is there a built-in function / 3rd party library which can deal with 1:many relationships efficiently?) </li>
  </ul>
  
  <p>There are then 3 possible options - are any of these philosophically better?:</p>
  
  <ul>
  <li><p>Modify the code so that the XML is generated without generating the array 1st</p></li>
  <li><p>Leave it as an array (as this seemed logical) and then use SimpleXML to rewrite it as XML (this also means that if I want to return the info as JSON, or any other format, I don't have rewrite the logic again and can just format the array) - however, is this particularly slow? Especially for a large number of RSS items?</p></li>
  <li><p>whichever of the above, I know some people who use PHP to write a static RSS file when the PHP is called (a new file is only generated if there is new data to be added), rather than generate the RSS file on the fly each time - are there any advantages to this method?</p></li>
  </ul>