Coming in late on this topic, but...

Database.

"SELECT firstname, lastname, address FROM TABLENAME ORDER BY lastname ASC";

Use ASC or DESC to order your query results. When you iterate over the
result as Torsten indicated, everything will be in the order you specify.
Check out the MySQL docs for all the information you'll ever need on sorting
and/or grouping results from a query.

Rich



> -----Original Message-----
> From: Pete Holsberg [mailto:[EMAIL PROTECTED]
> Sent: Friday, September 03, 2004 11:59 AM
> Cc: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Re: Newbie Questions
> 
> 
> On Thu, 2 Sep 2004, Torsten Roehr wrote:
> 
> > > I think I need just a little push in the right
> > > direction. After I send the above SELECT command, how
> > > do I get the result to appear on a web page?
> > 
> > mysql_query() will return a result set. There are
> > different functions to extract the rows from it. I would
> > recommend mysql_fetch_assoc() - it returns an associative
> > array of the current row/record set where the field names
> > of your table become the keys of the array. So if you
> > select firstname, lastname you will get an array like
> > this:
> > 
> > array('firstname' => 'My firstname', 'lastname' => 'My lastname')
> > 
> > Just loop through your result set to output/process the 
> data. Try this:
> > 
> > $result = mysql_query('SELECT firstname, lastname FROM table');
> > 
> > while ($row = mysql_fetch_assoc($result)) {
> > 
> >     echo $row['firstname'] . ' ' . $row['lastname'];
> > }
> > 
> 
> I want to display the sorted database. Which makes more
> sense: sorting the database table itself (either by address
> or by name), or sorting the array?
> 
> Thanks.
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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

Reply via email to