Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    SELECT DISTINCT only one result

    I am having a problem with a sql statement using the SELECT DISTINCT. It is only pulling one result from the database when printing the array. Here is the results.
    Array ( [0] => 99796-Sponsors [team] => 99796-Sponsors )

    Here is the results through myphpadmin

    99796-Sponsors
    98614-KDP / Future Educators
    98239-For Riley
    97008-Milan
    94795-Team Hope
    93583-The Ventilators
    93079-Samantha's Team of Love
    92200-Chelsea Rainbows
    91804-Team Hayden
    90293-Individual Walkers - Dalton

    Here is the code I am trying to use:
    PHP Code:
    $select_teams "SELECT DISTINCT team FROM great_strides WHERE file_name = '$_POST[file]'";
    $query_teams mysql_query($select_teams)  or die("A MySQL error has occurred.<br />Your Query: " $your_query "<br /> Error: (" mysql_errno() . ") " mysql_error());

    $results_teams mysql_fetch_array($query_teams);
      foreach(
    $results_teams as $team) {
        
    $select_team_leader="SELECT * FROM great_strides WHERE team = '$team' AND position= 'Team Leader'"
    Does anyone know why I am only getting the one result and not all possibles?

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    You're only fetching one row there:
    PHP Code:
    $results_teams mysql_fetch_array($query_teams); 
    Instead you should loop over all the rows in the resulting resource:
    PHP Code:
    while ($results_teams mysql_fetch_array($query_teams)){
    // do stuff


  • Users who have thanked venegal for this post:

    unclhos (06-01-2009)


  •  

    Tags for this Thread

    Posting Permissions

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