title: Grouping items in a foreach loop in PHP
body: <p>So, I'm trying to make a sort of user-market type thing. There's a database with <code>item_names</code>, basically describes the virtual items, then there's another table <code>market</code>, where when a user lists one of their items, it's put for sale on the user-user market.</p>
  
  <p>My only problem here is I want to group it by item name, referenced in the <code>item_name</code> table. I know I could do a bunch of if/else statements but that's extraneous not only because there's a lot of items, but also because I will add more items as time goes on. I want the end result to be something like</p>
  
  <pre><code>--[Water for sale]---------------------+
  
  [50 water for sale] [20 water for sale]
  
  [10 water for sale] [10 water for sale]
  
  --[Chips for sale]----------------------+
  
  [50 chips for sale] [20 chips for sale]
  
  [10 chips for sale] [10 chips for sale]
  </code></pre>
  
  <p>And so on, done dynamically. </p>
  
  <p>Any help?</p>