CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   SELECT DISTINCT only one result (http://www.codingforums.com/showthread.php?t=167716)

unclhos 05-31-2009 08:53 PM

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?

venegal 05-31-2009 09:02 PM

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




All times are GMT +1. The time now is 05:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.