Development more help please!

Discussion in 'Software' started by Headspark, 12 Oct 2005.

  1. Headspark

    Headspark Minimodder

    Joined:
    23 Feb 2005
    Posts:
    403
    Likes Received:
    2
    Hi could someone please help me with more SQL.

    I have a number of records with different years, 2005, 2002, 2001 etc etc. There are also lots of records with the same year.

    How would i go about getting all the unique dates from the database and then listing them in a drop down box, so that a user could select to see all the records from that year.

    Thanks in advance,

    Andy
     
  2. SJH

    SJH Minimodder

    Joined:
    24 Dec 2003
    Posts:
    1,427
    Likes Received:
    5
    Try:

    Code:
    $query = 'SELECT DISTINCT field_name FROM table_name ORDER BY whatever';
    $result = mysql_query($query,$dbconn); // where $dbconn is your connection string
    
    echo '<select name="years">';
    while($a_row = mysql_fetch_array($result)) {
      echo '<option>'. $a_row['field_name'] .'</option>';
    }
    echo '</select>';
    
    Hope this helps :)
     
  3. Dad

    Dad You talkin to me?

    Joined:
    15 Apr 2003
    Posts:
    5,375
    Likes Received:
    8
    Hmmm.. Interesting. I wasn't aware of the DISTINCT switch in the sql query. Over that, I really need to learn php.
     

Share This Page