Forms Question: Options

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

 



Hi everyone!

Can someone help me with this question?

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 ) ) {
     extract ( $one_line_of_data );
 }

 ?>


<-- Snip -->


              <?php
              
               while ( $data = mysql_fetch_array( $response, MYSQL_ASSOC)) {
                     print "<select name=\"gallery_name\">";
                 foreach ( $data as $option_value ) {
                     print "<option
value=\"$option_value\">$option_value</option>";
                  
                     }  print "</select>";
                   }
              
              ?>


<-- Snip -->

-- 
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