Re: sorting mysql results
| From: | Andrew Kreps | Date: | Tue, 11 Jan 2005 00:22:02 +0000 |
| Subject: | Re: sorting mysql results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-206042@lists.php.net to get a copy of this message | ||
On Mon, 10 Jan 2005 16:38:18 -0500, Sebastian
<sebastian@broadbandgaming.net> wrote:
> I have a list of rows in the database and i would like to sort them in two
> categories.
> example,
>
> echo $row['name'] . '-' . $row['type'];
>
> // output:
>
> row 1 - files
>
add order by
type to your sql statement, and then put something like
the following in your mysql loop:
// initialize $prevType above
if ($prevType !== $row['type'])
{
print "<hr>" . $row['type'] . "------<br>"; // Or
whatever you
want the header to look like
}
$prevType = $row['type'];
That should do the trick.