Display data category wise
<p>We have six categories Example :- a,b,c,d,e,f.</p>

<p>In each category we have products.</p>

<p>In a category i have 2 products &amp; in b category i have 1 product.</p>

<p>I'm fetching this data from database.</p>

<pre><code>product_id category_id
1                1
2                1
3                2
</code></pre>

<p>What should be best logic to display records, so two categories not display next to it.</p>

<p>Output product id like :- 1,3,2</p>
