Re: Forms Question: Options
| From: | Matthew Weier O'Phinney | Date: | Sun, 12 Dec 2004 02:00:33 +0000 |
| Subject: | Re: Forms Question: Options | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204082@lists.php.net to get a copy of this message | ||
* Steve Marquez <smarquez@marquez-design.com>:
> I created a photo upload utility with individual galleries that images can
> be uploaded into. In the MySQL database, there are multiple names of
> galleries, some are the same. I want to have a select menu to show just the
> unique names of the galleries.
>
> I have used:
>
> Select DISTINCT gallery_names from images_upload;
>
> I have about 15 records, ten are "GALLERY1" and 5 are "GALLERY2." When I
> use
> the DISTINCT, two are output. It works perfectly in the MySQL terminal.
>
> However, when I use the same in PHP as a web page, it only outputs one, the
> one with only 5 records.
>
> Here is the code:
>
> <?php
>
> // log into our local server using the MySQL root user.
> $dbh = mysql_connect( "hostname", "username", "password" );
>
> // select the database.
> mysql_select_db( "db" ) or die ( mysql_error() . "\n" );
>
> //and read it back for printing purposes.
> $get_table_data = "SELECT DISTINCT gallery_name FROM images_upload ORDER
> BY gallery_name DESC";
>
> $response = mysql_query( $get_table_data, $dbh );
>
> //now print it out for the user.
> if ( $one_line_of_data = mysql_fetch_array( $response ) ) {
It's only printing out one record because you're only fetching from the
results set once. Change that to :
while ($one_line_of_data = mysql_fetch_array($response)) {
and you should be set.
--
Matthew Weier O'Phinney | mailto:matthew@garden.org
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org