I've got some rows inside a mysql database table, I want to group them via a column called 'resource' and have that 'resource' displayed at the top of each group.
The 'resource' element is created from a user-input text field - I have no way of knowing what it will be, but some entries will belong to the same resource.
At the moment I have tried using two approaches;
The first called the mysql_fetch_array on the table twice, with one "SELECT DISTINCT resource FROM table" and then put those elements into an array ($res):
Code: Select all
<?php
[color=#00BF00]foreach[/color] ($res as $l) {
[color=#0000FF]echo[/color] [color=#FF0000]"<tr><td>$l</td></tr>"[/color];
[color=#FFBF00]//list row data within resource type[/color]
[color=#00BF00]while[/color] ($r = [color=#0000FF]mysql_fetch_array[/color]($fin)) {
[color=#00BF00]if[/color] ($r[[color=#FF0000]'resource'[/color]] [color=#0000FF]==[/color] $l) {
[color=#0000FF]echo[/color] $r[[color=#FF0000]'blahblah'[/color]];
}
}
}
?>
If my explanation is a bit hard to understand, I want the code to have:
Code: Select all
Resource1:
>>list rows which belong to this resource>>
Resource2:
>>list rows...>
etcat the moment that code puts out
Code: Select all
Resource1:
>>rows which belong to resource1>>
Resource2:
Resource3:
Resource4:
etc