RE: Re: Newbie Questions

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

 



On Fri, 3 Sep 2004, Hutchins, Richard wrote:

> > -----Original Message-----
> > From: Pete Holsberg [mailto:pjh@xxxxxxxx]
> > Sent: Friday, September 03, 2004 11:59 AM
> > Cc: php-db@xxxxxxxxxxxxx
> > Subject: Re:  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?
>
> 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.

In the database table itself, right? Does it make more
sense to do that than to leave the database alone, read it
into an array and then sort it anyway I want (there will be
at least two different sorted lists I want it to produce)?

> Check out the MySQL docs for all the information you'll
> ever need on sorting and/or grouping results from a
> query.

:-) That's like saying "check out 'man' for everything you
want to know about Unix commands. :-)

Thanks.

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux