SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot rrreview's Avatar
    Join Date
    Jul 2002
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help with select statements

    Let's say I have a table with the field 'Track'. There are many duplicates of this field (for example, there are 12 entries of 'Hart High', 8 entries of 'Saugus High', etc.), but I only want to select one of each; a "unique selection" if you will.

    Code:
    SELECT * FROM table
    The above will return all the results. How do I make a select statement to return one of each unique 'Track' (and eventually dump them into an array or variables)?

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume you only want to retrieve the track name and not the whole record. This should assign each unique result to $row[0] and then output it to screen before overwriting the array. If you want to store the data longer, then you should assign it to a permanent array at the point where it's output currently.
    PHP Code:
    <?php
     $myTable 
    "TrackTable";
     
    $myField "Track";
     
    $results mysql_query("SELECT DISTINCT '".$myField."' FROM ".$myTable);
     while(
    $row mysql_fetch_array($results)){
      echo(
    $row[$myField]."<br>");
     }
    ?>
    I've not tested this, but if it doesn't work then I'll set up some data to test.


    Andy
    From the English nation to a US location.

  3. #3
    SitePoint Zealot rrreview's Avatar
    Join Date
    Jul 2002
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works great, thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •