Re: Re: Newbie Questions

From: Date: Fri, 03 Sep 2004 15:58:56 +0000
Subject: Re: Re: Newbie Questions
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-36028@lists.php.net to get a copy of this message
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.

« previous php.db (#36028) next »