Re: sorting mysql results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 10 Jan 2005 16:38:18 -0500, Sebastian
<sebastian@xxxxxxxxxxxxxxxxxxx> 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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux