How to categorized results from SQL, display 6 columns and set colorize on every category
<p>I would like to ask for help on how to achieve this. I have this code below that pull records from DB and display it in 6 columns.</p>

<p>What I want to achieve is that, I want to display results on 6 columns but I want to categorize and set different color on every category.</p>

<p>let say i want to display the whole set of fruits starting from letter A with 6 columns with colors of gray, then below all letters starting with B with 6 columns with white color on background then below is C with gray colors in 6 columns. thanks.</p>

<pre><code>&lt;?php
fruits = $stmt-&gt;prepare("SELECT * FROM fruits ORDER by fruit_id ASC");
$fruits-&gt;execute();
$cols = 6;

do {
    echo "&lt;tr&gt;";
    for ($i = 1; $i &lt;= $cols; $i++) {
        $row = $fruits-&gt;fetch(PDO::FETCH_ASSOC);
        if ($row) {
            $fruit_id = $row['fruit_id'];
            $fruit_name = $row['fruit_name'];
?&gt;

&lt;td&gt;
  &lt;table&gt;
    &lt;tr valign="top"&gt;
      &lt;td&gt;
        &lt;?php echo '&lt;input type="checkbox" id="fruit_id[]" name="fruit_id[]" value="' . $fruit_id . '"/&gt;' . $fruit_name . "\n"; ?&gt;
      &lt;/td&gt;
      &lt;td width="30"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
&lt;/td&gt;
&lt;?php
        } else {
            echo "&lt;td&gt;&amp;nbsp;&lt;/td&gt;";
        }
    }
} while ($row);
?&gt;
</code></pre>
